Question

Why does this not resolve the datatemplate?

<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 TemplateSelector feels like an overkill.

Was it helpful?

Solution

DataType design suggests the presence of a directive x:Type like that:

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

See the MSDN for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top