I want a button to insert text that is selected in a listbox to a textbox. I am trying to use command for this, I will pass the current caret index as command parameter, then the Command handler will insert the selected text at this index. Is it possible? I don’t know how to refer to aTextBox.CaretIndex in a xaml
Share
This problem is similar to this question.
The point is that it is no use to bind the property CaretIndex since it is not a DependencyProperty, as you do not get notifications of value changes. Specifically, if you bind directly to CaretIndex the program will compile but the value of CaretIndex from the data binding will always be 0, even if you move the cursor in the textbox.
You can instead create an attached property that you could bind instead of CaretIndex.
A solution for that is proposed here where an attached property is added in order to bind the SelectedText property, which is also not a dependency property. The idea is the same.