私はWPFアプリケーションでDataGrid
コントロールを持っていて、チェックボックス列をその列の1つとして持っています。私は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ありがとう! –