twiner
❔ Custom DataTemplate for TextElements or alternative approaches
In WPF I'm working on a customized RichTextBox that will add TextElements that are bound to view models. I want to DataTemplates for this, but you can't put TextElements in a DataTemplate.
I've been looking into DataTemplate and FrameworkTemplate to see how they work, but its quite involved and maybe I'm over thinking this.
I want to be able to supply, in xaml preferably, a collection of mappings between a partially configure DataType and a template that will be bound to it.
This is the code I have for the association at the moment, making a copy of the DataContext is easy enough, but I don't know a what to do to make a copy of the ElementTemplate and maintain the binding information.
4 replies
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
10 replies