DataGrid 大小调整问题

发布于 2024-12-26 03:09:19 字数 951 浏览 0 评论 0原文

我正在尝试将数据加载到数据网格中,但我对大小做了一场噩梦。我的数据网格似乎占用了它想要的空间。我希望它加载到当前大小并在需要时显示滚动条。

有人可以解释一下尺寸是如何工作的吗谢谢。

示例:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难得心□动 2025-01-02 03:09:19

Height/Width 设置为 Auto 意味着控件应占用所需的空间。这意味着如果控件需要的空间多于 UI 中的可用空间,则可以拉伸父控件并占用它想要的空间。

删除 Height="Auto"Width="Auto" 来解决问题

如果问题仍然存在,请尝试设置 Horizo​​ntalAlignment垂直对齐拉伸。这将使控件自行增大或缩小以占用其可用的所有空间,但它不会扩展其所在的容器以占用额外的空间。

Setting the Height/Width to Auto 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" and Width="Auto" to fix the issue

If it is still giving you trouble, try setting HorizontalAlignment and VerticalAlignment to Stretch. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文