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 :).
Hi Tomaz,
I am glad you worked this out. If you don’t have any further questions on the matter please verify the forum thread as answered so it is of better help to other usesrs.
Thanks in advance.
Regards Petar.
I fixed it. When value has been set on view model and modified, XamTextEditor was first updated inside TextChanged event. then when dispatcher called to update the text again, text editor value was the same and did not update. I added a check, to completely prevent updating text editor from TextChanged event.
I found a problem. My test project is for .NET 4.0 and works. But when I tried to implement this in my .NET 3.5 application, it fails. Test project also fails when downgraded to 3.5. I found that event when text is set with BeginInvoke, text editor doesn't update the visible text (while text property is correctly set).