如何根据属性值禁用数据绑定 ListBox 项? [英] How to disable a databound ListBox item based on a property value?
本文介绍了如何根据属性值禁用数据绑定 ListBox 项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道是否以及如何根据属性值禁用数据绑定 ListBox
中的项目?
Does anyone know if and how one can disable items in a databound ListBox
based on the value of a property?
最好我想要一个 DataTrigger
,当某个属性为 false
时,禁用此项目(使其无法选择)而不影响 中的其他项目>ListBox
.
Preferably I would like a DataTrigger
which, when a certain property is false
, disables this item (make it impossible to select) without affecting other items in the 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:
You can use 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>
这篇关于如何根据属性值禁用数据绑定 ListBox 项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文