如何获取ContentControl解析DataTemplate [英] How to get ContentControl to resolve DataTemplate
本文介绍了如何获取ContentControl解析DataTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么这不能解析数据模板?
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>
编写TemplateSelector感觉像是一种过分的杀伤力。
Writing a TemplateSelector feels like an overkill.
推荐答案
DataType
设计表明存在指令 x:Type
之类的指令
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>
请参见 MSDN 了解更多信息。
这篇关于如何获取ContentControl解析DataTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文