我有一个矩形,我有一个故事板:
<Storyboard x:Key="PressAndHoldColorBar">
<ColorAnimationUsingKeyFrames Duration="0:0:10" FillBehavior="Stop" Storyboard.TargetName="rectWarning" Storyboard.TargetProperty="Fill">
<LinearColorKeyFrame KeyTime="0:0:0" Value="Green" />
<LinearColorKeyFrame KeyTime="0:0:7" Value="Yellow" />
<LinearColorKeyFrame KeyTime="0:0:10" Value="Red" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
<Rectangle Height="100" HorizontalAlignment="Left" Margin="12,328,0,0" Name="rectWarning" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top" Width="200">
我希望在按下另一个按钮时发生这种颜色更改,所以我试图以编程方式调用代码:
s = (Storyboard)this.Resources["PressAndHoldColorBar"];
s.Begin();
我把它缩小到第一个片段中的Storyboard.TargetName和TargetProperty(我想)。我只需要帮助找出如何使其完全发挥作用。
答案 0 :(得分:3)
想出来:
<Storyboard x:Name="PressAndHoldColorBar">
<ColorAnimationUsingKeyFrames Duration="0:0:10" FillBehavior="Stop" Storyboard.TargetName="rectWarning"
Storyboard.TargetProperty="(Fill).(SolidColorBrush.Color)">
<LinearColorKeyFrame KeyTime="0:0:0" Value="Green" />
<LinearColorKeyFrame KeyTime="0:0:7" Value="Yellow" />
<LinearColorKeyFrame KeyTime="0:0:10" Value="Red" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
你必须使用(填充)。(SolidColorBrush.Color)。它不喜欢(Shape.Fill)。