Bind selected text in TextBox to the view model in WPF and by MVVM

559 Views Asked by At

I am new to WPF and MVVM. I have a TextBox with some lines of text. I want to bind a piece of text highlighted by a user, to my ViewModel. How can I do this without coding in code behind?

1

There are 1 best solutions below

6
Mihaeru On

You cannot directly bind your selected text to a property. You have to implement a DependencyProperty and attach that but this is not trivial for beginners. A good explanation is here: MVVM and the TextBox's SelectedText property