0
我在我的WPF應用程序中有一個DataGrid
控件,並且我有一個複選框列作爲其中一列。我正在使用DataGridTemplate
來構建數據網格。我的目標是更改禁用複選框的任何複選框數據網格單元格的背景顏色。我的複選框列如下:禁用控件的DataGridTemplateColumn樣式WPF
<!-- style for the checkbox column cells -->
<Style x:Key="DefaultCheckboxCellStyle" TargetType="DataGridCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Background" Value="HotPink" />
</Trigger>
</Style.Triggers>
</Style>
...
<DataGridTemplateColumn Header="MyCheckBoxColumn" CellStyle="{StaticResource DefaultCheckboxCellStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="chk" IsChecked="{Binding MyChkChecked, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding Path=MyChkEnabled}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
...
沒有我做的似乎改變了殘疾人的複選框的單元格背景。我顯示禁用的複選框,但所有單元格本身仍處於啓用狀態。有沒有辦法將內部複選框控件的啓用值綁定到單元格?如果是這樣,我可以在我的觸發器中使用它。
非常感謝!
這樣做伎倆@Ed Plunkett謝謝! –