gpt4 book ai didi

c# - WPF C# 如何为 HighlightBrush 颜色设置动画?

转载 作者:行者123 更新时间:2023-11-30 12:30:41 25 4
gpt4 key购买 nike

我正在尝试为 ListView 的选定项目颜色设置动画。

我可以通过这段代码访问这个“属性”:

<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Blue">
</Style.Resources>

如何为这个“属性”设置动画?

 <Storyboard x:Key="MyStoryboard">
<ColorAnimation Storyboard.TargetName="MyList"
Storyboard.TargetProperty="{x:Static SystemColors.HighlightBrushKey}" // compilation error
To="Gray" Duration="0:0:1" />
</Storyboard>

非常感谢!

最佳答案

所以这里是 SampleStyle ;-)

它为 ListViewItem 使用模板,您可以在其中为 IsSelected-Property 添加带有 ColorAnimation 的 Stoyboard!

<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border x:Name="Bd" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
<Grid>
<GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<ContentPresenter x:Name="contentPresenter" Visibility="Collapsed" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="GridView.ColumnCollection" Value="{x:Null}">
<Setter TargetName="contentPresenter" Property="Visibility" Value="Visible"/>
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="Bd" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
From="Red" To="Blue" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="Bd" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
From="Blue" To="Transparent" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

关于c# - WPF C# 如何为 HighlightBrush 颜色设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15660589/

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