在VisualState中,将LinearGradientBrush设置为storyboard.targetProperty而不是纯色。

3
我想知道如何将Storyboard.TargetProperty设置为LinearGradientBrush而不是纯色。我对VisualStates不熟悉,如果我的问题没有提供足够的信息,请告诉我。我只是想设置渐变而不是纯色,但是无法弄清楚如何操作。谢谢您的帮助。我正在使用我在http://msdn.microsoft.com/en-us/library/ms753328.aspx上找到的示例进行工作。
 <VisualState x:Name="Disabled">
    <Storyboard>
        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).
                  (GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                            Storyboard.TargetName="Border">
                <EasingColorKeyFrame KeyTime="0"
                                     Value="{StaticResource DisabledControlDarkColor}" />
              </ColorAnimationUsingKeyFrames>
              <ColorAnimationUsingKeyFrames
                  Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"
                                            Storyboard.TargetName="Border">
                <EasingColorKeyFrame KeyTime="0"
                                     Value="{StaticResource DisabledForegroundColor}" />
              </ColorAnimationUsingKeyFrames>
              <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderBrush).
                  (GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                            Storyboard.TargetName="Border">
                <EasingColorKeyFrame KeyTime="0"
                                     Value="{StaticResource DisabledBorderDarkColor}" />
              </ColorAnimationUsingKeyFrames>
            </Storyboard>
          </VisualState>
1个回答

10
你粘贴的代码可以使现有渐变中的某些停止点动画化,该渐变已应用为背景属性。如果你只想用新的刷子(恰好是LinearGradientBrush)替换整个背景,可以使用ObjectAnimationUsingKeyFrames。甚至文档中都提供了这个例子:
      <Storyboard>

        <!-- ObjectAnimationUsingKeyFrames is used to animate properties that take
             an object as a value. This animation lasts for 4 seconds using 3 KeyFrames which
             swap different brush objects at regular intervals, making the background of the Page
             change. -->
        <ObjectAnimationUsingKeyFrames
          Storyboard.TargetProperty="Background"
          Duration="0:0:4" RepeatBehavior="Forever">
        <ObjectAnimationUsingKeyFrames.KeyFrames>

          <!-- Note: Only discrete interpolation (DiscreteObjectKeyFrame) is available for 
          use with ObjectAnimationUsingKeyFrames which merely swaps objects according to
          a specified timeline. Other types of interpolation are too problematic to apply
          to objects.  -->

          <!-- Using a DiscreteObjectKeyFrame, the Page Background suddenly changes 
               to a LinearGradientBrush after the first second of the animation. -->
          <DiscreteObjectKeyFrame KeyTime="0:0:1">
            <DiscreteObjectKeyFrame.Value>
              <LinearGradientBrush>
                <LinearGradientBrush.GradientStops>
                  <GradientStop Color="Yellow" Offset="0.0" />
                  <GradientStop Color="Orange" Offset="0.5" />
                  <GradientStop Color="Red" Offset="1.0" />
                </LinearGradientBrush.GradientStops>
              </LinearGradientBrush>
            </DiscreteObjectKeyFrame.Value>
          </DiscreteObjectKeyFrame>

          <!-- ... -->

当你这么说的时候,这真的很明显!谢谢! - Terco

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接