I have a TextBox with a ContextMenu in it. When the user right clicks inside the TextBox and chooses the appropriate MenuItem, I would like to grab the SelectedText in my viewmodel. I have not found a good way to do this the “MVVM” way.
So far I have my appliction utilizing Josh Smith’s way of MVVM. I am looking to tranfer over to Cinch. Not sure if the Cinch framework will handle issues like this. Thoughts?
There’s no straightforward way to bind SelectedText to a data source, because it’s not a DependencyProperty… however, it quite easy to create an attached property that you could bind instead.
Here’s a basic implementation :
You can then use it like that in XAML :