After ViewModels are added to the DocumentItemSource (type: ObservableCollection<ViewModelBase>) the template selector's SelectTemplate method is called; however, the problem is that the item parameter passed in is always null.
In the user control containing the docksite I set the data context, set up the static resources (templates and template selector), and then place the docksite:
<UserControl.DataContext>
<viewModels:MyViewModel />
</UserControl.DataContext>
<UserControl.Resources>
<DataTemplate x:Key="myTemplateA">
<views:MyViewA/>
</DataTemplate>
<DataTemplate x:Key="myTemplateB">
<views:MyViewB/>
</DataTemplate>
<templateSelectors:DocumentTemplateSelector
MyTemplateA="{StaticResource myTemplateA}"
MyTemplateB="{StaticResource myTemplateB}"
x:Key="documentTemplateSelector"/>
</UserControl.Resources>
<docking:DockSite x:Name="dockSite"
viewModels:DockSiteViewModelBehavior.IsManaged="true"
DocumentItemsSource="{Binding DocumentViewModelList}"
DocumentItemTemplateSelector="{StaticResource documentTemplateSelector}">
<docking:Workspace>
<docking:TabbedMdiHost/>
</docking:Workspace>
</docking:DockSite>
public class DocumentTemplateSelector : DataTemplateSelector
{
public DataTemplate MyTemplateA { get; set; }
public DataTemplate MyTemplateB { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
...
}
}
Any ideas on why the template selector would be receiving null items instead of the viewmodels that are added to the items source?
Do the viewmodels that I add to the items source need to implement anything special?
Or, is there any example usage of the DocumentItemTemplateSelector? I searched the sample browser but didn't find any examples there.
Thanks!
[Modified at 07/25/2011 03:24 PM]