5

I'm using WPF and have DataGrid with checkbox column. the problem is that I would like the checkbox to stretch and fill the cell

enter image description here

this is my XAML :

 <Grid>
    <Controls:DataGrid ItemsSource="{Binding Persons}" AutoGenerateColumns="False">
        <Controls:DataGrid.Columns>
            <Controls:DataGridTextColumn Binding="{Binding Name}"/>
            <Controls:DataGridTemplateColumn>
                <Controls:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox />
                    </DataTemplate>
                </Controls:DataGridTemplateColumn.CellTemplate>
            </Controls:DataGridTemplateColumn>
        </Controls:DataGrid.Columns>
    </Controls:DataGrid>
</Grid>
Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
Erez
  • 6,405
  • 14
  • 70
  • 124

1 Answers1

6

You can put the CheckBox in a Viewbox, there will still be a small margin though which probably belongs to some control's Template, you could either try and change that template or mess with the Margin if you want to.

<Viewbox Margin="-1">
    <CheckBox/>
</Viewbox>
H.B.
  • 166,899
  • 29
  • 327
  • 400