Implicit DataTemplate not working

Why is the following implicit DataTemplate not working? Only a commented inline DataTemplate will work.

Note. If I delete both DataTemplate s, I see a string representation of the fully ProductListView name of the ProductListView type.

 <Window.Resources> <DataTemplate DataType="vm:ProductListViewModel"> <v:ProductListView/> </DataTemplate> </Window.Resources> <TabControl ItemsSource="{Binding Tabs}" TabStripPlacement="Left"> <TabControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Key}"/> </DataTemplate> </TabControl.ItemTemplate> <TabControl.ContentTemplate> <DataTemplate> <ContentPresenter Content="{Binding Value}"> <!--ContentPresenter.ContentTemplate> <DataTemplate DataType="vm:ProductListViewModel"> <v:ProductListView/> </DataTemplate> </ContentPresenter.ContentTemplate--> </ContentPresenter> </DataTemplate> </TabControl.ContentTemplate> </TabControl> 
+8
wpf datatemplate
source share
1 answer

DataType requires the use of x:Type because the type of the Object property, so if you type DataType="ns:Type" , you set this to the string "ns:Type" . If the property type was Type (for example, Style.TargetType ), the XAML processor automatically converts this string value to Type .

So here you should write:

  <DataTemplate DataType="{x:Type vm:ProductListViewModel}"> <v:ProductListView/> </DataTemplate> 

( Object property type to allow XML data data template, see documentation for more information)

+11
source share

All Articles