views:

98

answers:

1

In a WPF based project I would like to bind the content of a TextBox to two sliders in such a way that first slider would start selection (from left or right based on a checkbox) from the n-th character (n being slider value) to the m-th character (based on second slider value). In essence I would like to specify selection range based on slider values.

How can I achieve it?

+1  A: 

Ideally, you would bind TextBox.SelectionStart and TextBox.SelectionLength to values from the slider. (Probably via a converter that implements IMultiValueConverer)

Unfortunately, you can't, because you can only bind Dependency Properties, and SelectionStart and SelectionLength are not dependency properties.

To solve this problem you would have to handle the OnValueChanged event on the sliders, then update the SelectionStart and SelectionLength properties via code in the event handler.

Disappointing answer - I bet you were hoping for some slick XAML code :-)

Andrew Shepherd
Yeah, that would be ideal but that other solution doesn't sound that hard. Thanks :)
kamilo