WPF中Trigger的Property有哪些

我自己常用的有IsMouseOver鼠标覆盖,IsSelected选中,IsFocused焦点,
IsPressed按下,IsEnabled可用,IsDefaulted默认,还有哪些希望有人补充。

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WPF,可以使用DataTrigger来绑定ListBox每个Item的Index属性,并根据其值来设置Trigger的行为。 以下是一个示例,演示如何在Trigger获取ListBox每个Item的Index: ```xml <ListBox x:Name="MyListBox"> <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem"> <Setter Property="Background" Value="White"/> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex)}" Value="0"> <Setter Property="Background" Value="LightBlue"/> </DataTrigger> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex)}" Value="1"> <Setter Property="Background" Value="LightGray"/> </DataTrigger> </Style.Triggers> </Style> </ListBox.ItemContainerStyle> <ListBoxItem Content="Item 1"/> <ListBoxItem Content="Item 2"/> <ListBoxItem Content="Item 3"/> <ListBoxItem Content="Item 4"/> <ListBoxItem Content="Item 5"/> </ListBox> ``` 在上面的示例,使用了ListBox的AlternationIndex属性来获取每个Item的Index。 AlternationIndex是WPF的一个内置属性,它为ListBox的每个Item提供了一个唯一的整数值,可以用于在Trigger设置行为。 在上面的示例,如果Index为偶数,则将该Item的背景色设置为LightGray,如果为奇数,则将其背景色设置为LightBlue。 注意:在使用AlternationIndex属性时,需要将ListBox的AlternationCount属性设置为一个大于1的值,以便为每个Item分配一个唯一的Index。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值