WPF - Centering a checkbox in a GridViewColumn?
Posted
by
Sonny Boy
on Stack Overflow
See other posts from Stack Overflow
or by Sonny Boy
Published on 2010-12-22T21:48:36Z
Indexed on
2010/12/22
21:54 UTC
Read the original article
Hit count: 281
Hey all,
I'm currently struggling on getting my checkboxes to property center within my GridViewColumns.
I've defined a style for my checkboxes like so:
<Style TargetType="{x:Type CheckBox}" x:Key="DataGridCheckBox">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="IsEnabled" Value="False" />
<Setter Property="Margin" Value="4" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Width" Value="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type GridViewColumn}},Path=ActualWidth}" />
</Style>
And my checkboxes are added into the GridViewColumn using a DataTemplate like this:
<GridViewColumn Header="Comment">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Style="{StaticResource DataGridCheckBox}" IsChecked="{Binding PropertyItem.Comment, Converter={StaticResource booleanConverter}, ConverterParameter='string'}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
But the problem I have is that the checkboxes remain left-aligned (even when resizing the column).
Any ideas?
Thanks in advance,
Sonny
© Stack Overflow or respective owner