我想将Background
属性设置为LinearGradientBrush
但似乎有很多约束,original code看起来像这样:
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
Storyboard.TargetProperty="(Panel.Background).
(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0"
Value="{StaticResource SelectedBackgroundColor}" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
我认为这可行:
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(LinearGradientBrush)">
<EasingColorKeyFrame KeyTime="0">
<EasingColorKeyFrame.Value>
<GradientStopCollection>
<GradientStop/>
<GradientStop/>
</GradientStopCollection>
</EasingColorKeyFrame.Value>
</EasingColorKeyFrame>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
但事实并非如此:
无法分配指定的值。以下类型是 预期:“颜色”。
属性“值”不支持类型的值 'GradientStopCollection'。
答案 0 :(得分:1)
这应该有效:
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<LinearGradientBrush>
<GradientStop Color="Red"/>
<GradientStop Color="Green" Offset="1"/>
</LinearGradientBrush>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>