xceedsoftware / wpftoolkit

All the controls missing in WPF. Over 1 million downloads.
Other
3.89k stars 877 forks source link

RichTextBox.TextChanged fires 6 times #660

Open xceedsoftware opened 7 years ago

xceedsoftware commented 7 years ago

josemartins[CodePlex]
Hello,

When I am using the RichTextBox control and attach the TextChanged event, if I make changes directly in the frontoffice, the event is fired 1 time for each change, but if I set the text in code like _myBox.text = quottestquot; the event is fired 6 times.

Has this happened to anyone? Can you suggest a solution?

Thanks in advance.

xceedsoftware commented 7 years ago

BoucherS[CodePlex]
The RichTextBox derives from System.Windows.Controls.RichTextBox Based on this : http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.textboxbase.textchanged(v=vs.110).aspx The RichTextBox from windows will fire the TextChange event when any content or formatting changes. Changing the Text will implicitly format the RichTextBox.

xceedsoftware commented 7 years ago

josemartins[CodePlex]
My workaround for this was the following: string _captionText = String.Empty; textBox.TextChanged += delegate { // To capture only one text changed fire event // of the total 6 that are fired if(_captionText != textBox.Text) { _captionText = textBox.Text; // Do something; } }; It's not prettiest of solutions, but it works for me.

xceedsoftware commented 7 years ago

MichaelHawker[CodePlex]
I've seen similar issues, I set the Text Binding UpdateSourceTrigger to LostFocus and the custom TextFormatter I have gets called for every keystroke.

It should only be called once when the Text property actually needs to change.

xceedsoftware commented 7 years ago

josemartins[CodePlex]
up!