WPF change DataGridCheckBoxColumn to red dots

I want to change my checkboxes to red dots, in the DataGridCheckBoxColumn of the data. Thus, the marked items are red dots, and the unverified items are empty. How to change style inside DataGridCheckBoxColumn?

+4
source share
1 answer

Try this, it is adapted from fooobar.com/questions/1667536 / ... , which was mentioned by Ansel Faillace in an earlier comment.

<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>
0
source

Source: https://habr.com/ru/post/1667532/


All Articles