【问题标题】:Animating the transition from Pressed to Normal button state动画从 Pressed 到 Normal 按钮状态的转换
【发布时间】:2014-01-20 07:23:51
【问题描述】:

我的Pressed 状态正在降低Button 内容的不透明度。

我想对从PressedNormal 的过渡进行动画处理,这样需要 3 秒才能发生。我尝试定义一个 VisualTransition 但它不起作用。按下我的按钮立即恢复正常,我看不到不透明度从0.5 逐渐恢复到1

<VisualStateGroup x:Name="CommonStates">
    <VisualStateGroup.Transitions>
        <VisualTransition From="Pressed"
                          To="Normal"
                          GeneratedDuration="0:0:3" />
    </VisualStateGroup.Transitions>
    <VisualState x:Name="Normal" />
    <VisualState x:Name="MouseOver" />
    <VisualState x:Name="Pressed">
        <Storyboard>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"
                                           Storyboard.TargetName="ContentContainer">
                <DiscreteObjectKeyFrame KeyTime="0"
                                        Value="0.5" />
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
    </VisualState>
</VisualStateGroup>

我想知道我做错了什么。

【问题讨论】:

  • 您是否使用混合来创建动画?您可以实时查看动画。用 blend 创建动画真的很容易。
  • 我没有使用 Blend。我现在刚刚尝试过,对于我来说如何使用这个工具来解决我的问题并不明显。
  • 用钥匙创建你的故事板(动画)。创建行为 => ControlStoryboardAction 并与您的控件链接。例如,在 1 秒内为不透明度从 0 到 1 的按钮创建动画。只要链接到另一个按钮,您就会看到动画。

标签: wpf xaml windows-phone-8


【解决方案1】:

它不能在手机上或使用鼠标的开发环境中工作吗? 如果是后者,您是否尝试将 VisualTransition 更改为 Pressed->MouseOver?使用鼠标时,不可能从按下->正常,因为鼠标仍然会结束。

除了这种可能性,乍一看一切都很好。

(我发现一个有用的资源是http://samples.msdn.microsoft.com/Silverlight/SampleBrowser/index.htm#/?sref=CustomTemplateSamples&id=4,虽然它对于 SilverLight 应该仍然对 WPF 有用)

【讨论】:

  • 无法在手机上工作(我无法尝试模拟器,因为我的 CPU 不兼容 SLAT)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-08
  • 2012-03-02
  • 2021-07-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-20
相关资源
最近更新 更多