gpt4 book ai didi

wpf - 将 LinearGradientBrush 而不是纯色设置为 VisualState 中的 storyboard.targetProperty

转载 作者:行者123 更新时间:2023-12-04 19:14:34 24 4
gpt4 key购买 nike

我想知道如何将 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>

最佳答案

您粘贴的代码会为现有渐变中的某些停止点设置动画,该渐变被应用为背景属性。如果你只想用一个新画笔(恰好是一个线性渐变画笔)替换整个背景,你可以使用 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>

<!-- ... -->

关于wpf - 将 LinearGradientBrush 而不是纯色设置为 VisualState 中的 storyboard.targetProperty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6024812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com