DataGrid 大小调整问题
我正在尝试将数据加载到数据网格中,但我对大小做了一场噩梦。我的数据网格似乎占用了它想要的空间。我希望它加载到当前大小并在需要时显示滚动条。
有人可以解释一下尺寸是如何工作的吗谢谢。
示例:
<Grid Name="MainUI" Height="Auto" Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid Name="MainGrid" Grid.Row="1" VerticalAlignment="Top" Height="Auto" Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TabControl TabStripPlacement="Bottom" Name="Main_Tab" VerticalAlignment="Top" Visibility="Visible" />
</Grid>
</Grid>
在选项卡控件中,我在后面的代码中的新选项卡项上创建一个数据网格,当发生这种情况时,数据网格会占用尽可能多的空间。
当我加载 itemTab 的数据网格时,它没有调整大小。
谢谢
I am trying to load data into a datagrid but I am having a nightmare with sizes. My datagrid seem to take as much space as it wants. I want it to load into the current size and display scroll bars if needed.
Could someone explain how the sizing works thank you.
Example:
<Grid Name="MainUI" Height="Auto" Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid Name="MainGrid" Grid.Row="1" VerticalAlignment="Top" Height="Auto" Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TabControl TabStripPlacement="Bottom" Name="Main_Tab" VerticalAlignment="Top" Visibility="Visible" />
</Grid>
</Grid>
Within the tab control I create a datagrid on a new tab item in the code behind when this happens, the datagrid takes as much room as possible.
The datagrid of itemTab has no sizing on it when I load it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
Height
/Width
设置为Auto
意味着控件应占用所需的空间。这意味着如果控件需要的空间多于 UI 中的可用空间,则可以拉伸父控件并占用它想要的空间。删除
Height="Auto"
和Width="Auto"
来解决问题如果问题仍然存在,请尝试设置
HorizontalAlignment
和垂直对齐
到拉伸
。这将使控件自行增大或缩小以占用其可用的所有空间,但它不会扩展其所在的容器以占用额外的空间。Setting the
Height
/Width
toAuto
means the control should take up as much space as it needs. This means if the control needs more space than is available in the UI, it's allowed to stretch the parent control and take up however much space it wants.Remove the
Height="Auto"
andWidth="Auto"
to fix the issueIf it is still giving you trouble, try setting
HorizontalAlignment
andVerticalAlignment
toStretch
. This will make the control will grow or shrink itself to take up all space available to it, however it won't expand the container it is in to take up additional space.