■ DataTemplate 클래스 : DataType 속성 사용하기

----------------------------------------------------------------------------------------------------

<Window

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:s="clr-namespace:System;assembly=mscorlib"

    Title="Content 속성 테스트">

    <Window.Resources>

        <DataTemplate DataType="{x:Type s:Int32}">

            <StackPanel Orientation="Horizontal">

                <TextBlock Text="Integer : " />

                <TextBlock Text="{Binding}" />

            </StackPanel>

        </DataTemplate>

        <DataTemplate DataType="{x:Type s:Double}">

            <StackPanel Orientation="Horizontal">

                <TextBlock Text="Double : " />

                <TextBlock Text="{Binding}" />

            </StackPanel>

        </DataTemplate>

        <DataTemplate DataType="{x:Type s:String}">

            <StackPanel Orientation="Horizontal">

                <TextBlock Text="String : " />

                <TextBlock Text="{Binding}" />

            </StackPanel>

        </DataTemplate>

        <DataTemplate DataType="{x:Type s:DateTime}">

            <StackPanel Orientation="Horizontal">

                <TextBlock Text="DateTime : "          />

                <TextBlock Text="{Binding Path=Month}" />

                <TextBlock Text="/"                    />

                <TextBlock Text="{Binding Path=Day}"   />

                <TextBlock Text="/"                    />

                <TextBlock Text="{Binding Path=Year}" />

            </StackPanel>

        </DataTemplate>

        <Style TargetType="{x:Type Button}">

            <Setter Property="HorizontalAlignment" Value="Center" />

            <Setter Property="Margin"              Value="12"     />

            <Setter Property="FontSize"            Value="12pt"   />

            <Setter Property="Padding"             Value="10"     />

        </Style>

    </Window.Resources>

    <StackPanel>

        <Button>

            <s:Int32>27</s:Int32>

        </Button>

        <Button>

            <s:Double>27.543</s:Double>

        </Button>

        <Button>

            27.543

        </Button>

        <Button>

            <x:Static Member="s:DateTime.Now" />

        </Button>

    </StackPanel>

</Window>

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요