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 を書くのはやり過ぎのように感じます。

4

1 に答える 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を参照してください。

于 2013-07-07T18:23:24.067 に答える