Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stretch the Checkbox to the cell size

Tags:

wpf

xaml

datagrid

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>
like image 230
Erez Avatar asked Sep 25 '11 11:09

Erez


1 Answers

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>
like image 132
H.B. Avatar answered Oct 18 '22 02:10

H.B.