I have a generic view where I "inject" some specific view into a contained ContentControl
(I created that feature with these help -> help 1 - help 2).
The basic source of my views are these:
MyGenericView.xaml
<UserControl x:Class="MyNS.MyGenericView"
... >
<UserControl.Resources>
<vml:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</UserControl.Resources>
<Grid DataContext="{Binding MyGenericViewModel, Source={StaticResource Locator}}">
<ContentControl Content="{Binding MyObject}" />
</Grid>
</UserControl>
CustomerView.xaml
<UserControl x:Class="AnotherNS.CustomerView"
... >
<Grid>
<StackPanel Orientation="Vertical">
<Label Content="Description" />
<TextBox Text="{Binding description}" />
</StackPanel>
</Grid>
</UserControl>
Crud.xaml
: a resource dictionary which I use to "solve" what's the correct view to show, depending on the DataType
of MyObject
object provided by the generic view.
<ResourceDictionary ... >
<DataTemplate DataType="{x:Type mo:Customer}">
<vw:CustomerView />
</DataTemplate>
<DataTemplate DataType="{x:Type mo:Product}">
<vw:ProductView />
</DataTemplate>
...
</ResourceDictionary>
It's working fine. I can manage MyObject
through the "specific" view (customer, product, etc).
Well. That's my problem:
All the specific views have their own ViewModels and, of course, they manage the respective views' data. But I don't know (on the viewmodel) what's the object (MyObject) I'm working with, because the Generic View provides it to the Specific View, not to the viewmodel.
Is there a way to let the ViewModels of the specific Views know the object which is "commanding" the view?