wpf - 在 WinRT 应用程序中为应用程序栏图标的可见性设置动画

标签 wpf xaml windows-8 winrt-xaml appbar

所有默认的 Windows 8 应用程序在显示和隐藏它们时(基于上下文更改)对其应用程序栏图标使用相同的淡入淡出动画。 This page谈到设置应用栏图标的可见性,但没有提到动画化它们。

我希望我的应用栏图标使用相同的动画。当一个图标变为隐藏时,它应该淡化为透明然后折叠,而当变为可见时则相反。实现此动画的最佳方法是什么?

最佳答案

您正在寻找与此类似的东西,您只需根据鼠标按下事件或某个值来触发 Storyboard。只是一个警告,下面提供的这些值是一个粗略的例子,你需要调整它们才能得到你想要的。您可以根据您当前组织代码的方式将 Storyboard 作为资源放置在许多地方。希望对您有所帮助。

<!-- IN -->
<Storyboard x:Name="FadeButtonIn">
  <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"
                                 Storyboard.TargetName="YourButtonObject">
    <EasingDoubleKeyFrame KeyTime="0:0:0.6"
                          Value="0" />
    <EasingDoubleKeyFrame KeyTime="0:0:1.6"
                          Value="1" />
  </DoubleAnimationUsingKeyFrames>
  <ObjectAnimationUsingKeyFrames Storyboard.TargetName="YourButtonObject"
                                 Storyboard.TargetProperty="(UIElement.Visibility)">
    <DiscreteObjectKeyFrame KeyTime="0">
      <DiscreteObjectKeyFrame.Value>
        <Visibility>Visible</Visibility>
      </DiscreteObjectKeyFrame.Value>
    </DiscreteObjectKeyFrame>
  </ObjectAnimationUsingKeyFrames>
</Storyboard>
<!-- OUT -->
<Storyboard x:Name="FadeButtonOut">
  <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"
                                 Storyboard.TargetName="YourButtonObject">
    <EasingDoubleKeyFrame KeyTime="0:0:0.6"
                          Value="1" />
    <EasingDoubleKeyFrame KeyTime="0:0:1.6"
                          Value="0" />
  </DoubleAnimationUsingKeyFrames>
  <ObjectAnimationUsingKeyFrames Storyboard.TargetName="YourButtonObject"
                                 Storyboard.TargetProperty="(UIElement.Visibility)">
    <DiscreteObjectKeyFrame KeyTime="0">
      <DiscreteObjectKeyFrame.Value>
        <Visibility>Collapsed</Visibility>
      </DiscreteObjectKeyFrame.Value>
    </DiscreteObjectKeyFrame>
  </ObjectAnimationUsingKeyFrames>
</Storyboard>

关于wpf - 在 WinRT 应用程序中为应用程序栏图标的可见性设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13645584/

相关文章:

c# - ItemsControl 忽略资源中的 DataTemplates

c# - 每个显示器 DPI 感知的 WPF 应用程序与 RibbonWindow

c# - WPF 将 ComboBox 绑定(bind)到我的 ViewModel

windows-8 - 适用于阿拉伯语的 Windows 8 Metro 风格字体

wpf - 如何在 F# 中编写 WPF 用户控件?

wpf - 获取路径或多段线上最接近断开点的点

c# - 将括号添加到文本框值

c# - Silverlight 嵌套自定义控件导致 StackOverflowException

node.js - 在NodeJS的操作系统模块中,有谁知道优胜美地或Windows8出现的平台是什么?

windows-8 - Windows 8/Windows Server 2012 中基于功能的安全性