c# - 禁用基于绑定(bind)值 WPF 的 ListBox 项的选择

标签 c# wpf listboxitem

<分区>

Possible Duplicate:
How to disable a databound ListBox item based on a property value?

我有一个列表框,我想根据绑定(bind)中的a 字段使列表框中的某些项目不可选择。

我试过将 listboxitem.IsEnabled 设置为 false,但这没有达到预期的效果。

如果可能的话,请有人指教。

这是我的数据模板:

<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>

最佳答案

如果你想禁用列表框中的单个项目,你可以尝试 this .您可以根据您的绑定(bind)属性来执行此操作。希望对您有所帮助。

关于c# - 禁用基于绑定(bind)值 WPF 的 ListBox 项的选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14400768/

相关文章:

c# - 从目录中选择随机文件

c# - WPF 中的 Aero 窗口 (C#)

c# - Unity - 无法访问对另一个脚本的引用

c# - 如何获得 IObservable 的最后已知值?

c# - 绑定(bind)到数据网格的 ObservableCollection - 使用工厂方法

.net - 何时使用 {x :Type …}?

WPF - ListBox 在绑定(bind) ItemsSource 时忽略样式

vba - ListBox 基于 ComboBox 填充 - 不同的数据结构

c# - 在事件发生时从 DataGridView 更新数据库无法正常工作