첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    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"
    Width="800"
    Height="600"
    Title="DataTemplate 엘리먼트 : DataType 속성을 사용해 Button 엘리먼트의 ContentTemplate 속성 설정하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <DataTemplate DataType="{x:Type s:Int32}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="정수 : "   />
                <TextBlock Text="{Binding}" />
            </StackPanel>
        </DataTemplate>
        <DataTemplate DataType="{x:Type s:Double}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="실수 : "   />
                <TextBlock Text="{Binding}" />
            </StackPanel>
        </DataTemplate>
        <DataTemplate DataType="{x:Type s:String}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="문자열 : " />
                <TextBlock Text="{Binding}" />
            </StackPanel>
        </DataTemplate>
        <DataTemplate DataType="{x:Type s:DateTime}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="날짜/시간 : "         />
                <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="10"     />
            <Setter Property="Padding"             Value="10"     />
        </Style>
    </Window.Resources>
    <Grid>
        <StackPanel
            HorizontalAlignment="Center"
            VerticalAlignment="Center">
            <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>
    </Grid>
</Window>
728x90
반응형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요