禁用基于绑定值 WPF 的 ListBox 项的选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14400768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable selection of an ListBox item based on binding value WPF
提问by user589195
Possible Duplicate:
How to disable a databound ListBox item based on a property value?
可能的重复:
如何根据属性值禁用数据绑定 ListBox 项?
I have a listboxand would like to make some of the items in the listbox non-selectable based on the a field in the binding.
我有一个listbox并且希望根据绑定中的 a 字段使列表框中的某些项目不可选择。
Ive tried setting the listboxitem.IsEnabledto false but this doesnt have teh desired effect.
我试过将 设置listboxitem.IsEnabled为 false 但这并没有达到预期的效果。
Please could someone advise if this is possible.
如果这可能的话,请有人建议。
Heres my datatemplate:
这是我的数据模板:
<DataTemplate x:Key="GridTemplate">
<StackPanel Orientation="Horizontal">
<Border Padding="{Binding EditorRow.RightBondIndent}" Width="50">
<Image x:Name="rightImg" Source="mat.png" Stretch="Fill" />
</Border>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding EditorRow.MaterialType}" Value="Blank">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>

