[FrmControlTemplate.xaml]


<UserControl x:Class="RiaTemplate.FrmControlTemplate"

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

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

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">

        <!--버튼의 모양을 직접 정의-->

        <Button Width="200" Height="100">

            <Button.Template>

                <ControlTemplate TargetType="Button">

                    <Border BorderBrush="Blue" BorderThickness="3">

                        <TextBlock Text="템플릿이 적용된 버튼"

                            HorizontalAlignment="Center" VerticalAlignment="Center" />

                    </Border>

                </ControlTemplate>

            </Button.Template>

        </Button>

    </Grid>

</UserControl>

 

 








[FrmTemplateByStyle.xaml]


<UserControl x:Class="RiaTemplate.FrmTemplateByStyle"

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

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

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">   

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.Resources>

            <!-- 스타일로 컨트롤 템플릿 구현 -->

            <Style x:Key="myButton" TargetType="Button">

                <Setter Property="Template">

                    <Setter.Value>

                        <ControlTemplate TargetType="Button">

                            <Border BorderBrush="Red" BorderThickness="3" Background="Yellow">

                                <TextBlock Text="템플릿이 적용된 버튼"

                                HorizontalAlignment="Center" VerticalAlignment="Center" />

                            </Border>

                        </ControlTemplate>

                    </Setter.Value>

                </Setter>   

            </Style>   

        </Grid.Resources>

        <StackPanel>

            <Button Width="200" Height="50" Content="버튼1" Style="{StaticResource myButton}" />

            <Button Width="200" Height="50" Content="버튼2" Style="{StaticResource myButton}" />

            <Button Width="200" Height="50" Content="버튼3" />

        </StackPanel>

    </Grid>

</UserControl>

 

 








[FrmTemplateBinding.xaml]


<UserControl x:Class="RiaTemplate.FrmTemplateBinding"

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

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

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.Resources>

            <!-- 스타일로 컨트롤 템플릿 구현 -->

            <Style x:Key="myButton" TargetType="Button">

                <Setter Property="Template">

                    <Setter.Value>

                        <ControlTemplate TargetType="Button">

                            <Border BorderBrush="Red" BorderThickness="3" Background="Yellow">

                                <TextBlock Text="{TemplateBinding Content}"

                                HorizontalAlignment="Center" VerticalAlignment="Center" />

                            </Border>

                        </ControlTemplate>

                    </Setter.Value>

                </Setter>

            </Style>

        </Grid.Resources>

        <StackPanel>

            <Button Width="200" Height="50" Content="버튼1" Style="{StaticResource myButton}" />

            <Button Width="200" Height="50" Style="{StaticResource myButton}">

                <Button.Content>

                    <TextBlock Text="버튼2"></TextBlock>

                </Button.Content>

            </Button>

            <Button Width="200" Height="50" Content="버튼3" Style="{StaticResource myButton}" />

        </StackPanel>

    </Grid>

</UserControl>

 

 








[FrmContentPresenter.xaml]


<UserControl x:Class="RiaTemplate.FrmContentPresenter"

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

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

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.Resources>

            <!-- 스타일로 컨트롤 템플릿 구현 -->

            <Style x:Key="myButton" TargetType="Button">

                <Setter Property="Template">

                    <Setter.Value>

                        <ControlTemplate TargetType="Button">

                            <Border BorderBrush="Red" BorderThickness="3" Background="Yellow">

                                <!--

                                <TextBlock Text="{TemplateBinding Content}"

                                HorizontalAlignment="Center" VerticalAlignment="Center" />

                                -->

                                <!-- ContentPresenter : 텍스트를 포함한 요소 자체를 표현 -->

                                <ContentPresenter />

                            </Border>

                        </ControlTemplate>

                    </Setter.Value>

                </Setter>

            </Style>

        </Grid.Resources>

        <StackPanel>

            <Button Width="200" Height="50" Content="버튼1" Style="{StaticResource myButton}" />

            <Button Width="200" Height="50" Style="{StaticResource myButton}">

                <Button.Content>

                    <TextBlock Text="버튼2" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>

                </Button.Content>

            </Button>

            <Button Width="200" Height="50" Content="버튼3" Style="{StaticResource myButton}" />

        </StackPanel>

    </Grid>

</UserControl>

 

 











Posted by holland14
: