我想在数据网格的DataGridCheckBoxColumn中将复选框更改为红点。因此,选中的项目为红点,未选中的项目为空。如何更改DataGridCheckBoxColumn中的样式?
答案 0 :(得分:0)
尝试这一点,它是根据stackoverflow.com/questions/1345961/在之前的评论中提到的Ansel Faillace改编的。
<DataGrid x:Name="dataGrid" Margin="10" ItemsSource="{Binding}">
<DataGrid.Resources>
<Style x:Key="GreenRedCheckBox" TargetType="{x:Type Checkbox}">
<Setter Property="HorizontalAlignment" Value="Center />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="innerBorder">
<Ellipse x:Name="statusLight"
Fill="Red"
Stretch="Fill"
Stroke="Black"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Height="10"
Width="10" />
</Border>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Fill" TargetName="statusLight" Value="Green" />
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter Property="Fill" TargetName="statusLight" Value="Red" />
</Trigger>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGrideCheckBoxColumn ElementStyle="{StaticResource GreenRedCheckBox}"
EditingElementStyle="{StaticResource GreenRedCheckBox}" />
</DataGrid.Columns>
</DataGrid>