【问题标题】:Bind WPF DataGrid column to another将 WPF DataGrid 列绑定到另一个
【发布时间】:2010-06-04 02:34:13
【问题描述】:

我想根据其相邻 DataGridComboBoxColumn 的 SelectedValue 是否 == 'Other' 来启用/禁用 DataGridTextColumn

我可以在下面的 ListBox 中进行这项工作,但这在我的 DataGrid 环境中不起作用,因为 DataGridComboBox 列没有 name 属性。

<ListBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Source={StaticResource CustomData}}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <ComboBox Name="operatorComboBox" SelectedValue="{Binding OperatorId}" ItemsSource="{Binding Source={StaticResource Operator}}" SelectedValuePath="Id" DisplayMemberPath="Name"></ComboBox>
                <TextBox Text="{Binding Name}"  Visibility="{Binding Path=SelectedValue, ElementName=operatorComboBox, Converter={StaticResource intToVis}}"></TextBox>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

那么这可以用 DataGrid 完成吗?

(我知道我已经更改了 ListBox 示例中的可见性,但将其更改为启用并不是一个巨大的飞跃。(显然,在适当的 DataGrid 中隐藏整个列将是一件坏事)

this 的问题与我所问的非常相似,我只是无法将解决方案分解成我所追求的

【问题讨论】:

    标签: wpf datagrid binding


    【解决方案1】:

    我能想到的解决这个问题的最简单方法实际上是创建一个 DataGridTemplateColumn 而不是 DataGridTextBoxColumn 然后在模板内创建一个文本框。为了禁用/启用文本框,请将 IsEnabled 属性绑定到基础 OperatorId 属性。您还必须编写一个 ValueConverter 来检查 OperatorId 值是否 == 'Other' 并返回该值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-11
      • 1970-01-01
      • 2010-12-16
      • 2011-04-13
      • 2013-07-28
      • 1970-01-01
      相关资源
      最近更新 更多