How to make a wpf datagrid fill all available space and resize with window? Mind that the datagrid is inside a grid.
You should be able to do it for a datagrid (or for any WPF control) by setting HorizontalAlignment
and VerticalAlignment
to Stretch
If it's inside a Grid, you should be able to set something like this
<Grid> <!-- parent grid or whatever -->
<DataGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ... >
</DataGrid>
</Grid>
Remove all height and width property of its parent control. remove horizontal and vertical property. Define row height as * of its parent grid.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" >
</DataGrid>
</Grid>
Set the width for the last column of the DataGrid to *.
<DataGridTextColumn Header="Notes"
Binding="{Binding Notes}"
Width="*"/>
Note : This actually works on only the last column of the DataGrid
Insert DataGrid directly to the Grid without wrapping with a panel.
<Grid>
<DataGrid>
</DataGrid>
</Grid>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.