Silverlight:将GradientBrush资源用于状态动画

Silverlight:将GradientBrush资源用于状态动画,silverlight,gradient,visualstatemanager,brush,Silverlight,Gradient,Visualstatemanager,Brush,我有一组控件(Button、ToggleButton),我希望具有相同的样式,因此我在我的ResourceDictionary中为正常/禁用/启用状态创建了一些渐变笔刷,例如“ButtonFillBrush”、“ButtonFillMouseOverBrush”等。这些被定义为全局可重用笔刷资源 我知道可以在状态内更改动画中渐变的各个停止点,例如: <VisualState x:Name="MouseOver"> <Storyboard> <Col

我有一组控件(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的答案和更多搜索:


所以,如果有一个画笔动画或其他东西会很好


Rogier

您可以找到更多关于资源词典及其使用的信息。但是,对于您的彩色动画问题,有关Silverlight动画(包括彩色动画)的许多信息可以在此链接上找到

嘿,Niels,这不起作用,因为它需要的是颜色而不是画笔。但是关于StaticResource的部分确实帮助我找到了正确的答案,所以我的编辑He你可以用字典中的颜色替换画笔,然后我猜。我最近才开始使用Silverlight for Windows Phone,所以我的知识非常有限:P.很高兴你能理解!
<VisualState x:Name="MouseOver">
  <Storyboard>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backgroundRectangle"                      
Storyboard.TargetProperty="Fill">
      <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource ButtonFillMouseOverBrush}" />
    </ObjectAnimationUsingKeyFrames>
  </Storyboard>
</VisualState>