■ ControlTemplate 엘리먼트 : 컨트롤 템플리트 설정 엘리먼트에서 정의한 속성 바인딩 하기

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

<Button

    x:Class="TestProject.MonoButton"

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

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

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

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

    xmlns:local="clr-namespace:TestProject"

    ...

    Foreground="Black">

    <Button.Template>

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

            <ControlTemplate.Resources>

            ...

            </ControlTemplate.Resources>

            <Grid Name="grid"

                Width="{TemplateBinding Width}"

                Height="{TemplateBinding Height}">

                <Ellipse Name="ellipse"

                    HorizontalAlignment="Stretch"

                    VerticalAlignment="Stretch"

                    StrokeThickness="1"

                    Stroke="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Regular}"

                    Fill="Transparent" />

                <Path Name="path"

                    HorizontalAlignment="Center"

                    VerticalAlignment="Center"

                    StrokeThickness="2"

                    Stroke="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Regular}"

                    Fill="Transparent" />

            </Grid>

            <ControlTemplate.Triggers>

                ...

            </ControlTemplate.Triggers>

        </ControlTemplate>

    </Button.Template>

</Button>

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

※ Regular 속성은 Button을 상속한 MonoButton 클래스에서 정의한 의존 속성이다.

Posted by 사용자 icodebroker