■ VisualStateManager 엘리먼트 사용하기

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

<Grid x:Name="grid"

    xmlns:sw="clr-namespace:System.Windows;assembly=System.Windows">

    <Grid.Resources>

        <ControlTemplate

            x:Key="ButtonControlTemplateKey"

            TargetType="Button">

            <Grid >

                <sw:VisualStateManager.VisualStateGroups>

                    <sw:VisualStateGroup x:Name="CommonStates">

                        <sw:VisualStateGroup.Transitions>

                            <sw:VisualTransition                  To="Normal"    GeneratedDuration="0:0:0.2" />

                            <sw:VisualTransition                  To="MouseOver" GeneratedDuration="0:0:1"   />

                            <sw:VisualTransition From="MouseOver" To="Pressed"   GeneratedDuration="0:0:0.5" />

                            <sw:VisualTransition                  To="Disabled" GeneratedDuration="0:0:0"    />

                        </sw:VisualStateGroup.Transitions>

                        <sw:VisualState x:Name="Normal" />

                        <sw:VisualState x:Name="MouseOver">

                            <Storyboard>

                                <ColorAnimation

                                    Storyboard.TargetName="ellipseSolidColorBrush"

                                    Storyboard.TargetProperty="Color"

                                    To="Blue" />

                            </Storyboard>

                        </sw:VisualState>

                        <sw:VisualState x:Name="Pressed">

                            <Storyboard>

                                <ColorAnimation

                                    Storyboard.TargetName="ellipseSolidColorBrush"

                                    Storyboard.TargetProperty="Color"

                                    To="Red" />

                            </Storyboard>

                        </sw:VisualState>

                        <sw:VisualState x:Name="Disabled">

                            <Storyboard>

                                <ColorAnimation

                                    Storyboard.TargetName="ellipseSolidColorBrush"

                                    Storyboard.TargetProperty="Color"

                                    To="Gray" />

                            </Storyboard>

                        </sw:VisualState>

                    </sw:VisualStateGroup>

                </sw:VisualStateManager.VisualStateGroups>

                <Ellipse>

                    <Ellipse.Fill>

                        <SolidColorBrush

                            x:Name="ellipseSolidColorBrush"

                            Color="Gold" />

                    </Ellipse.Fill>

                </Ellipse>

                <ContentPresenter

                    x:Name="contentPresenter"

                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"

                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"

                    Margin="{TemplateBinding Padding}"

                    ContentTemplate="{TemplateBinding ContentTemplate}"

                    Content="{TemplateBinding Content}" />

            </Grid>

        </ControlTemplate>

    </Grid.Resources>

    <Button

        Width="100"

        Height="50"

        Template="{StaticResource ButtonControlTemplateKey}"

        Content="버튼" />

</Grid>

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요