在 ListBoxItem 的 ControlTemplate 中的 VisualState 中设置背景 属性?
Setting Background property inside VisualState in the ControlTemplate of ListBoxItem?
我想将 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>
但事实并非如此:
The specified value cannot be assigned. The following type was
expected: "Color".
Property 'Value' does not support values of type
'GradientStopCollection'.
这应该有效:
<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>
我想将 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>
但事实并非如此:
The specified value cannot be assigned. The following type was expected: "Color".
Property 'Value' does not support values of type 'GradientStopCollection'.
这应该有效:
<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>