WPF 使用EventTrigger设置Item的IsSelected选项
最主要的是在ItemContainerStyle中设置EventTrigger。
使用其他具有items的控件时也是可以通用类似的代码
截图
xaml代码
<Grid> <ListBox x:Name="c" > <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem"> <Style.Triggers> <EventTrigger RoutedEvent="Selected"> <BeginStoryboard> <Storyboard Storyboard.TargetProperty="IsSelected"> <BooleanAnimationUsingKeyFrames> <DiscreteBooleanKeyFrame KeyTime="0:0:0:0.1"> <DiscreteBooleanKeyFrame.Value> <num:Boolean>False</num:Boolean> </DiscreteBooleanKeyFrame.Value> </DiscreteBooleanKeyFrame> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> </Style.Triggers> </Style> </ListBox.ItemContainerStyle> <ListBoxItem Content="AAAA" /> <ListBoxItem Content="BAAA" /> <ListBoxItem Content="ACAAA"/> <ListBoxItem Content="ADAA" /> <ListBoxItem Content="AEAA"/> </ListBox> </Grid>