How to get ContentControl to resolve DataTemplate

▼魔方 西西 提交于 2019-12-23 14:21:51

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/17514824/how-to-get-contentcontrol-to-resolve-datatemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!