I need to call a method when TextBox changes, but TextBox.Caret isn’t a DependencyProperty, and because of that there is no possibilty to bind it. How to know when the caret position changes?
I need to call a method when TextBox changes, but TextBox.Caret isn’t a DependencyProperty
Share
You can try to handle
SelectionChangedevent of theTextBox.In XAML you define your text box like this:
Next, you write method handling the cursor change:
It fires on every caret change, so on getting focus, on moving cursor with arrow keys, on changing cursor position with mouse etc.
If you need this behaviour in several text boxes, you can also just create your own clas based on
TextBoxand create your own event in a similar manner.I’ve tested this in a WPF project, but it should work in Silverlight project as well.