How to make a wpf datagrid fill all available space and resize with window? Mind that the datagrid is inside a grid.
如何使wpf数据网格填充所有可用空间并使用窗口调整大小?请注意,数据网格位于网格内。
4 个解决方案
#1
20
You should be able to do it for a datagrid (or for any WPF control) by setting HorizontalAlignment
and VerticalAlignment
to Stretch
您应该能够通过将HorizontalAlignment和VerticalAlignment设置为Stretch来为数据网格(或任何WPF控件)执行此操作
If it's inside a Grid, you should be able to set something like this
如果它在Grid中,你应该可以设置这样的东西
<Grid> <!-- parent grid or whatever -->
<DataGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ... >
</DataGrid>
</Grid>
#2
10
- Never set height or width to it or its parent control
- 切勿为其或其父控件设置高度或宽度
- No need to worry on the horizontal and vertical alignment since by default Horizontal and vertical alignment are stretch. if above are proper things should work :)
- 无需担心水平和垂直对齐,因为默认情况下水平和垂直对齐是拉伸的。如果以上是适当的事应该工作:)
#3
4
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>
#4
0
Insert DataGrid directly to the Grid without wrapping with a panel.
将DataGrid直接插入Grid,而不用面板包装。
<Grid>
<DataGrid>
</DataGrid>
</Grid>
#1
20
You should be able to do it for a datagrid (or for any WPF control) by setting HorizontalAlignment
and VerticalAlignment
to Stretch
您应该能够通过将HorizontalAlignment和VerticalAlignment设置为Stretch来为数据网格(或任何WPF控件)执行此操作
If it's inside a Grid, you should be able to set something like this
如果它在Grid中,你应该可以设置这样的东西
<Grid> <!-- parent grid or whatever -->
<DataGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ... >
</DataGrid>
</Grid>
#2
10
- Never set height or width to it or its parent control
- 切勿为其或其父控件设置高度或宽度
- No need to worry on the horizontal and vertical alignment since by default Horizontal and vertical alignment are stretch. if above are proper things should work :)
- 无需担心水平和垂直对齐,因为默认情况下水平和垂直对齐是拉伸的。如果以上是适当的事应该工作:)
#3
4
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>
#4
0
Insert DataGrid directly to the Grid without wrapping with a panel.
将DataGrid直接插入Grid,而不用面板包装。
<Grid>
<DataGrid>
</DataGrid>
</Grid>