【问题标题】:remove the animation on a Button when click in a universal App在通用应用程序中单击时删除按钮上的动画
【发布时间】:2016-02-22 20:34:20
【问题描述】:

我在这样的通用应用程序中为我的按钮定义了这种样式,当我点击它时,我试图删除影响到按钮的动画

<Style TargetType="Button" x:Key="BtnStyle">
    <Setter Property="Foreground" Value="White"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid x:Name="RootGrid" Background="{TemplateBinding Background}">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal">
                                <Storyboard>
                                    <PointerUpThemeAnimation Storyboard.TargetName="RootGrid" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="PointerOver">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid"
                                               Storyboard.TargetProperty="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="White" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="BorderBrush">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="#1d84eb" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <PointerDownThemeAnimation Storyboard.TargetName="RootGrid" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Pressed">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid"
                                               Storyboard.TargetProperty="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="White" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="BorderBrush">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="#1d84eb" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <PointerDownThemeAnimation Storyboard.TargetName="RootGrid" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <ContentPresenter x:Name="ContentPresenter"
                      BorderBrush="Transparent"
                      BorderThickness="{TemplateBinding BorderThickness}"
                      Content="{TemplateBinding Content}"
                      ContentTransitions="{TemplateBinding ContentTransitions}"
                      ContentTemplate="{TemplateBinding ContentTemplate}"
                      Padding="{TemplateBinding Padding}"
                      HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                      VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                      AutomationProperties.AccessibilityView="Raw"
                                      Foreground="White"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

当我点击按钮时,如何删除按钮上的动画 感谢帮助

【问题讨论】:

    标签: c# win-universal-app windows-10-universal


    【解决方案1】:
    <VisualState x:Name="Pressed">
    
    </VisualState>
    

    只需删除 &lt;VisualState x:Name="Pressed"&gt; 状态下的所有内容。

    编辑

    或者删除整个&lt;VisualState x:Name="Pressed"&gt;

    【讨论】:

    • 感谢您的回复,但这会删除我按下按钮时对按钮有影响的颜色?请问有什么方法可以删除动画并且按下时不改变颜色?
    • 绝对清楚:你有“PointerOver”蓝白色动画 - 没关系。因此,您只想在指针结束时更改按钮颜色,而不是在单击按钮时更改按钮颜色?只需删除 Pressed VisualState
    猜你喜欢
    • 2012-10-20
    • 2016-05-07
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 2020-10-19
    • 2017-11-30
    相关资源
    最近更新 更多