我有一个列表框,定义了DataTemplate, Style和ItemContainerStyle。
这个列表框有SelectionMode="Single"
最初所有项目都有Opacity="0.7"
,当项目被选中时,我将其设置为Opacity="1"
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Setters>
<Setter Property="Opacity" Value="0.7"/>
</Style.Setters>
<Style.Triggers>
<DataTrigger Binding="{Binding IsEventLocked}" Value="False">
<Setter Property="IsEnabled" Value="False"/>
<Setter Property="Opacity" Value="0.2"/>
</DataTrigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Opacity" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>
但我也需要使所有其他(未选定)项目与Opacity="0.2"
,直到选定的项目将被取消选择。
简而言之:[Initial (Opacity=0.7)]->[ItemSelected = {(SelectedItem:Opacity=1), (All Unselected items: Opacity=0.2)}]->[Item Deselected (SelectedItem==null) =(Opacity=0.7)]
谢谢你的建议和想法!
触发点:选区存在&&自己没有被选中
应该这样做:
<Style TargetType="ListBoxItem">
<Setter Property="Opacity" Value="0.7" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}"
Value="false" />
<Condition
Binding="{Binding SelectedItems.Count, RelativeSource={RelativeSource AncestorType=ListBox}}"
Value="1" />
</MultiDataTrigger.Conditions>
<Setter Property="Opacity" Value="0.2" />
</MultiDataTrigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Opacity" Value="1" />
</Trigger>
</Style.Triggers>
</Style>