【问题标题】:WPF Datagrid TemplateColumn Control Enable and DisableWPF Datagrid TemplateColumn 控件启用和禁用
【发布时间】:2023-03-16 04:10:01
【问题描述】:

我有带有两个 TemplateColumn 的 Datagrid。

第一列是组合框,第二列带有扩展的 IntergerUpDown 控件

我需要根据 Combox 框 SelectedItem 的值启用/禁用 IntegerUpDown 控件。

请帮助我如何做到这一点。下面是示例 xaml。

<Grid><DataGrid ItemsSource="{Binding List1}" Name="x1">
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="ColorTemplate">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox  ItemsSource="{Binding DataContext.List2, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}}" 
                                      DisplayMemberPath="Name"  SelectedValue="{Binding ColourId}" SelectedValuePath="Id" Tag="{Binding Id}"
                                       HorizontalAlignment="Stretch" x:Name="discussTemplate" VerticalAlignment="Stretch"
                                         />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="UPDown" Width="Auto">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <extToolkit:IntegerUpDown AllowSpin="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Minimum="0"
                                                  x:Name="updown"
                                                  IsEnabled="????" >

                            </extToolkit:IntegerUpDown>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>

【问题讨论】:

    标签: wpf wpfdatagrid


    【解决方案1】:

    这可以通过 ViewModel ColourId 属性上的 DataTrigger 轻松完成。

    由于 ComboBox 上的 SelectedValue 属性已绑定,因此您可以在 extToolkit:IntegerUpDown 控件上使用 DataTrigger,该控件将根据 ViewModel 上的 ColourId 值将 IsEnabled 设置为 True/False。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-27
      • 1970-01-01
      • 2019-03-20
      • 1970-01-01
      • 2017-10-09
      • 1970-01-01
      • 2023-03-08
      • 2012-10-04
      相关资源
      最近更新 更多