如何使ContentControl解析DataTemplate

4
为什么这个数据模板没有被解析?
<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>

编写一个TemplateSelector感觉有点过度设计了。

尝试使用:<DataTemplate DataType="{x:Type system:DateTime}">。或许会有帮助。 - Anatoliy Nikolaev
1个回答

3

DataType 的设计暗示了存在一个像这样的指令 x:Type

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

请查看MSDN了解更多信息。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接