wpf datagridcheckboxcolumn style
13,660
Solution 1
You can use DataGridTemplateColumn to create a custom checkboxcolumn
<Custom:DataGridTemplateColumn x:Name="gdchk" Header="Test" MaxWidth="50">
<Custom:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<CheckBox IsChecked="{Binding Path = classname}" HorizontalAlignment="Center" Style="{DynamicResource myCheckBoxStyle}"/>
</DataTemplate>
</Custom:DataGridTemplateColumn.CellTemplate>
</Custom:DataGridTemplateColumn>
Hope this helps.
Solution 2
You can simply use your defined style with ElementStyle attribute.
Style defined in resources:
<Style x:Key="MyCheckBoxStyle" TargetType="{x:Type CheckBox}"> ... </Style>
And my datagrid checkbox column:
<DataGridCheckBoxColumn ElementStyle="{StaticResource MyCheckBoxStyle}" Binding="{Binding someValue}" />
Solution 3
try this
<DataGridCheckBoxColumn MinWidth="100"
Binding="{Binding Path=BoolValue}"
Header="Bool Column"
IsThreeState="True">
<DataGridCheckBoxColumn.ElementStyle>
<Style TargetType="CheckBox">
<Setter Property="Background" Value="{Binding BoolValueColour, Converter={StaticResource MyConverter}}" />
</Style>
</DataGridCheckBoxColumn.ElementStyle>
</DataGridCheckBoxColumn>
Comments
-
Eduardo Brites almost 2 years
Imagine I have a CheckBox custom style named "MyCheckBoxStyle".
How can I make a Datagrid style that embeds a custom DataGridCheckBoxColumn style based on my MyCheckBoxStyle?