gpt4 book ai didi

wpf - 如何防止 WPF 触发器在退出时重置原始值

转载 作者:行者123 更新时间:2023-12-04 05:46:08 29 4
gpt4 key购买 nike

我使用触发器有一个鼠标悬停选择 ListView :

<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsSelected" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>

但是,当鼠标移出时,触发器设置 IsSelected返回 false,这在此处是不需要的。有没有办法让触发器只在进入时设置而不是在退出时重置?

最佳答案

这是什么EventTriggers是给:

Unlike Trigger, EventTrigger has no concept of termination of state, so the action will not be undone once the condition that raised the event is no longer true.



例如,在您的情况下:
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsSelected">
<DiscreteBooleanKeyFrame KeyTime="0" Value="True" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>

关于wpf - 如何防止 WPF 触发器在退出时重置原始值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10661545/

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