Hi,
I'm defining a DataTemplate in App.xaml that ultimately gets bound to a viewmodel. The problem I have is that the MainViewModel has a property that's also a viewmodel (NestedViewModel). The bindings throw an exception saying that the NestedViewModel property doesn't exist on MainViewModel even though I know that it does. Here's a sample to explain:
DataTemplate in App.xaml
<DataTemplate x:Key="mainViewModelTemplate">
<controls:customListView ItemsSource="{Binding Path=MyNestedViewModel.ListItems, Mode=TwoWay}" ShowAddView="{Binding Path=MyNestedViewModel.ShowAddView, Mode=TwoWay}"
ShowEditView="{Binding Path=MyNestedViewModel.ShowEditView, Mode=TwoWay}" SelectedItem="{Binding Path=MyNestedViewModel.SelectedListItem, Mode=TwoWay}"/>
</DataTemplate>
Code Displaying Template (NOTE: _viewService takes a viewModel type, finds the associated datatemplate, and returns the view from DataTemplate.CreateContent)
var view = _viewService.GetView(mainViewModel.GetType()) as View;
if (view != null)
{
view.BindingContext = mainViewModel;
}
contentView.Content = view;
Any ideas or suggestions? Or should this work?
Thanks