Sanity check on WPF CustomControl Binding to ViewModel not working
Can someone sanity check me here...
In WPF I have a custom control derived from RichTextBox.
I needed to have a way to access the selected text from my ViewModel so I could use it to inject into a new object created by said VM
However, the value doesn't seem to move across the binding into the view model.
So on my view model I made a SelectedText Property
and in my custom RichTextBox I have a DependencyProperty
Finally, in my test Window I have it bound together
When inspecting the UI with Snoop, I can see that the binding on SelectedText is considered valid.
I believe that using SetCurrentValue is correct to allow the value to propagate across the binding to the ViewModel
So I must be missing something, I've done this what feels like countless times and I just don't see what I'm overlooking
6 Replies
I have verified that the SelectionChanged callback is executed and that the value of Selection.Text is the expected value (the text that appears to be visually selected in the UI)
I also tried changing the binding on Selected text to update on property change.
I think you need mode=twoway off the top of my head
😐 well that was it
I've barely started my day and I feel like I should end it
haha, glad I remembered right
Thank you for the sanity check!
I clearly have lost it
it happens to everyone, no problem