Erez
Erez

Reputation: 6446

Stretch the Checkbox to the cell size

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>

Upvotes: 5

Views: 4003

Answers (1)

brunnerh
brunnerh

Reputation: 185290

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>

Upvotes: 6

Related Questions