Silverlight:使用 GradientBrush 资源进行状态动画

发布于 2024-10-10 02:59:31 字数 1875 浏览 3 评论 0原文

我有一组控件(Button、ToggleButton),我想要具有相同的样式,因此我在 ResourceDictionary 中为正常/禁用/启用状态创建了一些渐变画笔,例如“ButtonFillBrush”、“ButtonFillMouseOverBrush”等。这些是定义为全局可重复使用的画笔资源。

我知道可以更改状态内动画中渐变的各个停止点,例如:

<VisualState x:Name="MouseOver">
   <Storyboard>
      <ColorAnimation Duration="0" To="#FF041D06" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="path" d:IsOptimized="True"/>
      <ColorAnimation Duration="0" To="#FF118519" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="backgroundRectangle" d:IsOptimized="True"/>
    </Storyboard>
</VisualState>

现在,我知道可以在 VisualState Manager 中执行以下操作:

<VisualState x:Name="MouseOver">
   <Storyboard>
      <ColorAnimation Duration="0" To="ButtonFillMouseOverBrush" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush)" Storyboard.TargetName="backgroundRectangle" d:IsOptimized="True"/>
    </Storyboard>
</VisualState>

谢谢!

更新:使用有关 StaticResource 引用的答案和更多搜索: http://wildermuth.com/2008/07/18/Animating_Brushes_with_ObjectAnimationUsingKeyFrames

<VisualState x:Name="MouseOver">
  <Storyboard>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backgroundRectangle"                      
Storyboard.TargetProperty="Fill">
      <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource ButtonFillMouseOverBrush}" />
    </ObjectAnimationUsingKeyFrames>
  </Storyboard>
</VisualState>

所以,如果有一个 BrushAnimation 之类的东西就好了......

Rogier

I have a set of controls (Button, ToggleButton) I want to have the same style, so I have created a few gradient brushes for normal/disabled/enabled states in my ResourceDictionary, e.g. "ButtonFillBrush", "ButtonFillMouseOverBrush" etc. These are defined as global reusable Brush Resources.

I know it is possible to change individual stops of a gradient in a animation inside a state, for example:

<VisualState x:Name="MouseOver">
   <Storyboard>
      <ColorAnimation Duration="0" To="#FF041D06" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="path" d:IsOptimized="True"/>
      <ColorAnimation Duration="0" To="#FF118519" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="backgroundRectangle" d:IsOptimized="True"/>
    </Storyboard>
</VisualState>

Now, I know it is possible in the VisualState Manager to do something like:

<VisualState x:Name="MouseOver">
   <Storyboard>
      <ColorAnimation Duration="0" To="ButtonFillMouseOverBrush" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush)" Storyboard.TargetName="backgroundRectangle" d:IsOptimized="True"/>
    </Storyboard>
</VisualState>

Thanks!

Update: using the answer about the referring with the StaticResource and some more searching: http://wildermuth.com/2008/07/18/Animating_Brushes_with_ObjectAnimationUsingKeyFrames

<VisualState x:Name="MouseOver">
  <Storyboard>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backgroundRectangle"                      
Storyboard.TargetProperty="Fill">
      <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource ButtonFillMouseOverBrush}" />
    </ObjectAnimationUsingKeyFrames>
  </Storyboard>
</VisualState>

So, it would be nice to have a BrushAnimation or something...

Rogier

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢欲 2024-10-17 02:59:31

您可以找到有关资源词典和资源词典的更多信息。它们的使用此处。但是,对于您的彩色动画问题,可以在此链接上找到有关 Silverlight 动画(包括彩色动画)的大量信息 Silverlight 动画快速入门

You can find more information regarding Resource Dictionaries & the use of them here. However for your color animation question a lot of information regarding Silverlight animations (including color animations) can be found on this link Silverlight Animations Quickstart

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文