Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top