数据网格延伸到窗口之外
嘿大家。我的窗口中的数据网格有问题。我希望它仅在没有填充整个窗口时扩展到所需的大小,或者在它占据整个屏幕时显示滚动条。这是我的 xaml
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" Name="dg">
<DataGrid.Columns>
<DataGridTextColumn Header="Col1"/>
<DataGridTextColumn Header="Col1"/>
</DataGrid.Columns>
</DataGrid>
<GroupBox Grid.Row="2" Margin="5">
<Button>Click</Button>
</GroupBox>
</Grid>
如果我将数据网格的行高设置为 * ,它会将数据网格的灰色背景向下延伸到整行。但如果我将高度设置为自动,那么当窗口的项目太多时,它不会显示滚动条。
有什么想法吗?
Hey everyone. I have a problem with a datagrid in my window. I want it to extend only to its needed size if it doesn't fill the entire window or show a scroll bar if it does take up the entire screen. Here's my xaml
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" Name="dg">
<DataGrid.Columns>
<DataGridTextColumn Header="Col1"/>
<DataGridTextColumn Header="Col1"/>
</DataGrid.Columns>
</DataGrid>
<GroupBox Grid.Row="2" Margin="5">
<Button>Click</Button>
</GroupBox>
</Grid>
If I set the row height for the datagrid to * it extends the datagrid's gray background down the entire row. But if I set the height to auto, then it won't show a scrollbar when there are too many items for the window.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过将 DataGrid 嵌套在 ScrollViewer 中?
Have you tried nesting the DataGrid in a ScrollViewer?
我认为问题可能出在其他地方。我在本地尝试了您的代码并创建了一些数据。见下文:
我创建了一些数据,如下所示:
结果是一个正确的滚动条控件:
以及在另一个方向:
除非我完全误解了您的问题?
更新:添加了全屏截图:
I think the problem might be elsewhere. I tried your code locally and created some data. See below:
I created some data like so:
The result is a properly scrollbar-ed control:
And in the other direction:
Unless I'm completely misunderstanding your question?
UPDATE: Added full screen shot: