WPF Custom Style DataGridCheckBoxColumn?

Is there any way to check the box? iv tried to define a style for the checkbox, but that didn't work.

after using mole, it seems that the checkbox control has no ToggleButton, instead it uses BulleDecorator, im not sure about it the first time im using mole.

What I want to achieve is that instead of a checkbox, I want a red or green circle.

<Style TargetType="{x:Type CheckBox}">
    <Setter Property="IsHitTestVisible" Value="False"/>
    <Setter Property="Focusable" Value="False"/>
    <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 Fill="#FFFF0000" Stroke="#FF000000" Stretch="Fill" x:Name="statusLight" Width="15" Height="15" Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                </Border> 
                <ControlTemplate.Triggers> 
                    <Trigger Property="IsChecked" Value="True"> 
                    <Setter TargetName="statusLight" Property="Fill" Value="#FF00FF00" />
                    </Trigger> 
                     <Trigger Property="IsChecked" Value="False"> 
                    <Setter TargetName="statusLight" Property="Fill" Value="#FFFF0000" />
                    </Trigger> 
                </ControlTemplate.Triggers> 
            </ControlTemplate> 
        </Setter.Value> 
    </Setter>
</Style>
0
source share
2 answers

It looks like you are looking for the DataGridBoundColumn.ElementStyle property (DataGridCheckBoxColumn comes from DataGridBoundColumn). If this does not work for you, you can always use the DataGridTemplateColumn to display everything you want.

Vincent Sibal, .

+3

:

<Controls:DataGridCheckBoxColumn Header="Homme"  Binding="{Binding Homme}">
      <Controls:DataGridCheckBoxColumn.ElementStyle>
           <Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}"/>
     </Controls:DataGridCheckBoxColumn.ElementStyle>
</Controls:DataGridCheckBoxColumn>
+6

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


All Articles