绑定基于Checkbox属性的DataGrid TextBox Enable [英] Bind DataGrid TextBox Enable based on Checkbox property

查看:46
本文介绍了绑定基于Checkbox属性的DataGrid TextBox Enable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有复选框&的DataGrid;其他文本框。

I have a DataGrid with a Checkbox & other Textbox.

   <DataGrid AutoGenerateColumns="False" Height="170" Name="dataGrid1" Width="527"  OpacityMask="#FF161A1A" BorderBrush="#FFB7B39D" Background="LightYellow" RowBackground="LightGray" AlternatingRowBackground="#FFFFFFF5" BorderThickness="10" CanUserResizeRows="False" CanUserReorderColumns="False" CanUserResizeColumns="True" CanUserSortColumns="False" FontFamily="Segoe UI" FontSize="13" CanUserAddRows="False">

       <DataGrid.Columns>
            <DataGridCheckBoxColumn Header="" Binding="{Binding BoolProperty, Mode=TwoWay}" />
            <DataGridTextColumn Header="" Binding="{Binding header}" MinWidth="108" IsReadOnly="True" />
            <DataGridTextColumn Header="Number of Cases" Binding="{Binding cases}" >
            <DataGridTextColumn.EditingElementStyle>
                  <Style TargetType="TextBox">
                        <Setter Property="IsEnabled" Value="{Binding Path=BoolProperty, Mode=TwoWay}" />
                 </Style>
           </DataGridTextColumn.EditingElementStyle>
          </DataGridTextColumn>

checkboxcolumn绑定到 BoolProperty。我要的是如果BoolProperty为false则禁用文本框 Number of Cases,而如果BoolProperty为true则启用文本框。我尝试在TExtBox中添加IsEnabled,但无法正常工作。我要去哪里错了?

The checkboxcolumn is bind to a "BoolProperty". I want is Textbox "Number of Cases" to be disabled if the BoolProperty is false and enable if the BoolProperty is true. I tried adding the IsEnabled in TExtBox, but it doesn't work. Where am I going wrong ?

推荐答案

对于仅限XAML的方法,请改用模板列。 IsReadOnly isn'在细胞水平上可结合。由于该链接未提供实现,因此我会提供。

For an XAML only approach, use a template column instead. IsReadOnly isn't bindable at the cell level. Since that link doesn't provide implementation, I will.

<DataGridTemplateColumn>
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=myProperty}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <TextBox IsEnabled="{Binding Path=myBool}" Text="{Binding Path=myProperty, Mode=TwoWay}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>

这篇关于绑定基于Checkbox属性的DataGrid TextBox Enable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆