I know I can bind a control, say TextBox to a CheckBox value using the following code:
<CheckBox Name="cb1" />
<TextBox IsEnabled="{Binding ElementName=cb1, Path=IsChecked}" />
How can I do the same in a DataGrid ?
I have a DataGrid:
<DataGrid Name="xDataGridName" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="Enable">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<flatcheckbox:FlatCheckBox x:Name="xDGCheck" Margin="0" IsChecked="{Binding Path=Enabled, Mode=TwoWay}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<flatcheckbox:FlatCheckBox x:Name="xDGCheck" Margin="0" IsChecked="{Binding Path=Enabled, Mode=TwoWay}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Group">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Name="xTextBlockName" Text="{Binding Path=Group}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<!-- this is always enabled, i want it to be enable only when checkbox is checked -->
<TextBlock Name="xTextBlockName" Text="{Binding Path=Group}" IsEnabled="{Binding ElementName=xDGCheck, Path=IsChecked}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
How can implement the binding in a DataGrid ?
FlatCheckBox? Can it be replaced with just usualCheckBox, or it's important for the question?Enabledsource property.IsEnabled="{Binding Path=Enabled}, if you are anyway propagating the state into the VM?FlatCheckBoxis just a CheckBox with custom styling applied to it. And I'm binding it to the checkbox value ( and not toEnabled) because I want the textbox to be enabled/disabled immediately when I check/uncheck the checkbox. Binding it to Enabled, I have to check the checkbox, lose focus of the row, only then the textbox becomes enabled, and vice versa