个人资料

跳过导航链接首页 > 博客列表 > 博客正文

XAML button style 无边框+缩放动画

:


    <Style x:Key="ControlButtonStyle" TargetType="ButtonBase">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Margin" Value="0" />
        <Setter Property="Foreground" Value="{ThemeResource ApplicationForegroundThemeBrush}" />
        <Setter Property="MinWidth" Value="0" />
        <Setter Property="MinHeight" Value="0" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="UseSystemFocusVisuals" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ButtonBase">

                    <Border Padding="0" Margin="0" x:Name="ButtonEllipse" BackgroundSizing="InnerBorderEdge" BorderThickness="2" RenderTransformOrigin="0.5,0.5">
                        <Border.RenderTransform>
                            <CompositeTransform x:Name="btn_ellipse_transform" Rotation="1" ScaleX="1" ScaleY="1" />
                        </Border.RenderTransform>


                        <ContentPresenter toolkit_ui:FrameworkElementExtensions.Cursor="Hand" x:Name="Text" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="PointerOver">
                                    <Storyboard>

                                        <DoubleAnimation Storyboard.TargetName="btn_ellipse_transform" Storyboard.TargetProperty="ScaleX" Duration="0:0:0.1" To="1.1"></DoubleAnimation>
                                        <DoubleAnimation Storyboard.TargetName="btn_ellipse_transform" Storyboard.TargetProperty="ScaleY" Duration="0:0:0.1" To="1.1"></DoubleAnimation>


                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard Duration="0:0:0.2">

                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="btn_ellipse_transform" Storyboard.TargetProperty="ScaleX">

                                            <LinearDoubleKeyFrame KeyTime="0:0:0" Value="1"></LinearDoubleKeyFrame>
                                            <LinearDoubleKeyFrame KeyTime="0:0:0.1" Value="0.9"></LinearDoubleKeyFrame>
                                            <LinearDoubleKeyFrame KeyTime="0:0:0.2" Value="0.9"></LinearDoubleKeyFrame>
                                        </DoubleAnimationUsingKeyFrames>

                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="btn_ellipse_transform" Storyboard.TargetProperty="ScaleY">

                                            <LinearDoubleKeyFrame KeyTime="0:0:0" Value="1"></LinearDoubleKeyFrame>
                                            <LinearDoubleKeyFrame KeyTime="0:0:0.1" Value="0.9"></LinearDoubleKeyFrame>
                                            <LinearDoubleKeyFrame KeyTime="0:0:0.2" Value="0.9"></LinearDoubleKeyFrame>
                                        </DoubleAnimationUsingKeyFrames>


                                    </Storyboard>


                                </VisualState>

                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                    </Border>



                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

songshizhao
最初发表2024/10/12 0:04:10 最近更新2024/10/12 0:04:10 245
为此篇作品打分
10