How to Automatically Use a DataTemplate Based on ContentControl's Current Content's DataType
- 阅读更多 关于 How to Automatically Use a DataTemplate Based on ContentControl's Current Content's DataType
When I attempt to specify multiple DataTemplates for use by a ContentControl so that the correct one (based on Type) is used, I end up with Content that is simply the Content's ToString() value. <ContentControl DataContext="{Binding MyTreeRootViewModels}" Content="{Binding /, Path=CurrentlySelectedTreeViewModel}"> <ContentControl.Resources> <DataTemplate DataType="x:Type vm:TypeAViewModel"> <StackPanel> <local:TypeAUserControl /> </StackPanel> </DataTemplate> <DataTemplate DataType="x:Type vm:TypeBViewModel"> <StackPanel> <local:TypeBUserControl /> </StackPanel> </DataTemplate> <