This is what I'm trying to do:
- I'm writing a UserControl that I want to be consumed by other developers.
I want end users to be able to use my control using Dependency Properties.
<lib:ControlView ControlsText={Binding Path=UsersOwnViewModelText} />
I'm using the MVVM pattern.
I'm binding my ViewModels to their View's using
<DataTemplates>
.<DataTemplate DataType="{x:Type local:ControlViewModel}">
<local:ControlView />
</DataTemplate>
So I have two questions:
Am I right in thinking that if a UserControl is being consumed in XAML then the UserControl must set the ViewModel as its
DataContext
when the control'sLoaded
event fires instead of using the<DataTemplate>
method?How do I allow users to data bind to my control's dependency properties while still being data bound to my ViewModel?