I am trying to link a WPF window on top of a ViewModel that contains two collections: A and B. I am trying to use DataTemplates to display A or B depending on the setting of a flag in my ViewModel.
To this end, I set the DataContext = ViewModel window. However, when I try to associate a ContentControl with this DataContext and apply a DataTemplateSelector to it, the item parameter of the select SelectTemplate(object item, DependencyObject container) method SelectTemplate(object item, DependencyObject container) always null:
<Window [snip] Title="MainWindow"> <Window.Resources> </Window.Resources> <Grid> <ContentControl Content="{Binding}" ContentTemplateSelector="{StaticResource templateSelector}" /> </Grid> </Window>
How should I bind this ContentControl so that the WindowModel is passed into its DataTemplateSelector ?
source share