有谁知道是否以及如何禁用数据绑定(bind)中的项目ListBox
基于属性(property)的值(value)?
最好我想要一个 DataTrigger
其中,当某个属性是 false
, 禁用此项目(使其无法选择)而不影响 ListBox
中的其他项目.
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Name="textBlock" Text="{Binding Description}"/>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsEnabled}" Value="False">
??
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
最佳答案
您可以使用 ItemContainerStyle:
<ListBox>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding YourPropertyName}" Value="False">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
关于wpf - 如何根据属性值禁用数据绑定(bind)的 ListBox 项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1824543/