When I type into XamTextEditor, I want to modify the text sometimes while typing. What I do now is handle TextChanged event and if text is not correct, I want to set it to something else by doing text="..." inside the handler. The problem is that TextEditor doesn't update the visible text in the editor, although it's text value has internally changed (when I read a value it's correct). Doing this in WPF's TextBox it works.
How do I do this or is there another way?
Best regards
Tomaz
Hello Tomaz,
I have been looking through your case and have found a way for you to achieve your goal. Since the TextChanged event is fired simultaneously as the change takes place, every action you do inside the event has a chance to take a higher thread priority and be overridden when the NewValue
is actually applied. You can overcome this by ensuring that your code takes a lower priority using the Dispatcher class like so:
private void xamTextEditor1_TextChanged(object sender, RoutedPropertyChangedEventArgs<string> e)
{
if (e.NewValue=="textt")
Dispatcher.BeginInvoke(new Action(() => { xamTextEditor1.Text= "text"; }), System.Windows.Threading.DispatcherPriority.DataBind, null);
}
Please let me know if you require any further assistance on the matter.
Sincerely,
Petar Monov
Developer Support Engineer
Infragistics Bulgaria
www.infragistics.com/support
Thanks, this works :). I will do further testing and embed the code in my project.
Although, whatever text I set inside TextChanged event, it's actually set, but XamtextEditor does not reflect changes visually. It's "Text" property value and value displayed are not in sync. For example, if I read a value from "Text" property it's correct, but text editor shows different value :).