첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ DataTemplate 엘리먼트를 사용해 Button 엘리먼트의 ContentTemplate 속성을 설정하는 방법을 보여준다.

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"
    Width="800"
    Height="600"
    Title="DataTemplate 엘리먼트 : Button 엘리먼트의 ContentTemplate 속성 설정하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <ControlTemplate x:Key="ButtonControlTemplateKey" TargetType="Button">
            <Grid >
                <Ellipse>
                    <Ellipse.Fill>
                        <LinearGradientBrush
                            StartPoint="0.5 0"
                            EndPoint="0.5 1">
                            <GradientStop Color="Yellow" Offset="0" />
                            <GradientStop Color="Red"    Offset="1" />
                        </LinearGradientBrush>
                    </Ellipse.Fill>
                </Ellipse>
                <ContentPresenter Name="contentPresenter"
                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                    Margin="{TemplateBinding Padding}"
                    ContentTemplate="{TemplateBinding ContentTemplate}"
                    Content="{TemplateBinding Content}" />
            </Grid>
        </ControlTemplate>
        <DataTemplate x:Key="ButtonDataTemplateKey">
            <StackPanel Orientation="Horizontal">
                <Ellipse
                    Margin="0 0 10 0"
                    Width="5"
                    Height="5"
                    Fill="Black" />
                <ContentPresenter Content="{Binding}" />
            </StackPanel>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <Button
            Width="100"
            Height="100"
            FontWeight="Bold"
            Content="테스트"
            Template="{StaticResource ButtonControlTemplateKey}"
            ContentTemplate="{StaticResource ButtonDataTemplateKey}" />
    </Grid>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요