■ DataTemplate 엘리먼트 사용하기

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

<Grid x:Name="_pGrid">

    <Grid.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

                    x: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>

    </Grid.Resources>

    <Button

        Width="100"

        Height="50"

        FontSize="12"

        FontWeight="Bold"

        Content="버튼"

        Template="{StaticResource ButtonControlTemplateKey}"

        ContentTemplate="{StaticResource ButtonDataTemplateKey}" />

</Grid>

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

Posted by 사용자 icodebroker

댓글을 달아 주세요