How to get ContentControl to enable DataTemplate

Why does this not allow the data file?

<Window.Resources> <DataTemplate DataType="system:DateTime" > <Grid Background="Aqua"> <TextBlock Text="{Binding Day}"></TextBlock> </Grid> </DataTemplate> </Window.Resources> <Grid> <ContentControl Content="{x:Static system:DateTime.Now}"/> </Grid> 

Writing a Selector pattern seems redundant.

+4
source share
1 answer

DataType design assumes the existence of an x:Type directive, like this:

 <DataTemplate DataType="{x:Type system:DateTime}"> <Grid Background="Aqua"> <TextBlock Text="{Binding Day}" Height="30" Width="100" HorizontalAlignment="Center" /> </Grid> </DataTemplate> 

See MSDN for more details.

+3
source

Source: https://habr.com/ru/post/1490154/


All Articles