WPF DataGrid 内部手风琴高度问题

发布于 2024-08-24 22:50:54 字数 1634 浏览 6 评论 0原文

我正在使用最新的 WPF 工具包,但当我有一个大型记录集绑定时遇到高度问题到 AccordionItem 项内的 DataGrid 中。 Accordion 本身的高度可以很好地缩放,但是手风琴控件内的 DataGrid 不会获得 ScrollBar 或以任何方式受到约束,因此记录被隐藏。

我知道我很可能错过了一些非常简单的东西(比如从 DataGrid 的 height 属性到 Accordion 的绑定,但这看起来很混乱)

这里是代码的精简版本(是的,如果您绑定在一个大记录集中,这也会有同样的问题)

<UserControl>
<layouttoolkit:Accordion x:Name="ReportSelector" HorizontalAlignment="Stretch">
    <layouttoolkit:AccordionItem Header="grid 1">
        <dg:DataGrid
         AutoGenerateColumns="False"
         CanUserAddRows="False"
         CanUserDeleteRows="False"
         SelectionMode="Single">
...
            </dg:DataGrid.Columns>
        </dg:DataGrid>

    </layouttoolkit:AccordionItem>
    <layouttoolkit:AccordionItem Header="grid 2">
        <dg:DataGrid
         AutoGenerateColumns="False"
         CanUserAddRows="False"
         CanUserDeleteRows="False"
         SelectionMode="Single">
...
            </dg:DataGrid.Columns>
        </dg:DataGrid>

    </layouttoolkit:AccordionItem>
    <layouttoolkit:AccordionItem Header="grid 3">
        <dg:DataGrid
         AutoGenerateColumns="False"
         CanUserAddRows="False"
         CanUserDeleteRows="False"
         SelectionMode="Single">
...
            </dg:DataGrid.Columns>
        </dg:DataGrid>

    </layouttoolkit:AccordionItem>            
</layouttoolkit:Accordion>
</UserControl>

I am using the latest WPF Toolkit but am running into a height issue when I have a large record set bound into a DataGrid inside an AccordionItem item. The height of the Accordion itself scales nicely but the DataGrid inside the accordion control doesn't get get a ScrollBar or get constrained in any way so the records are hidden.

I know that I am most probably missing something very simple (like a binding from the DataGrid's height property to the Accordion but that seems messy)

here is a cut down version of the code (and yes, this has the same problem if you bind in a big recordset)

<UserControl>
<layouttoolkit:Accordion x:Name="ReportSelector" HorizontalAlignment="Stretch">
    <layouttoolkit:AccordionItem Header="grid 1">
        <dg:DataGrid
         AutoGenerateColumns="False"
         CanUserAddRows="False"
         CanUserDeleteRows="False"
         SelectionMode="Single">
...
            </dg:DataGrid.Columns>
        </dg:DataGrid>

    </layouttoolkit:AccordionItem>
    <layouttoolkit:AccordionItem Header="grid 2">
        <dg:DataGrid
         AutoGenerateColumns="False"
         CanUserAddRows="False"
         CanUserDeleteRows="False"
         SelectionMode="Single">
...
            </dg:DataGrid.Columns>
        </dg:DataGrid>

    </layouttoolkit:AccordionItem>
    <layouttoolkit:AccordionItem Header="grid 3">
        <dg:DataGrid
         AutoGenerateColumns="False"
         CanUserAddRows="False"
         CanUserDeleteRows="False"
         SelectionMode="Single">
...
            </dg:DataGrid.Columns>
        </dg:DataGrid>

    </layouttoolkit:AccordionItem>            
</layouttoolkit:Accordion>
</UserControl>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

十年不长 2024-08-31 22:50:54

看起来我最初的想法是正确的 - 我能够解决这个问题的唯一方法是将 DataGridMaxHeight 绑定到 ActualHeight > 的 AccordionItem

将以下属性添加到每个 DataGrid 就可以了

MaxHeight="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type layouttoolkit:AccordionItem}},Path=ActualHeight}"

Looks like my initial idea was right - the only way I have been able to solve this one is to bind the MaxHeight of the DataGrid to the ActualHeight of the AccordionItem

Adding the following property to each DataGrid did the trick

MaxHeight="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type layouttoolkit:AccordionItem}},Path=ActualHeight}"
雪落纷纷 2024-08-31 22:50:54

我很高兴我偶然发现了这个!此 QA 需要投票。除了列宽之外,我也遇到了类似的问题。

我的 DataGrid 有 Width="Auto",以及一些 * 大小的列宽度。在 Accordion 外部,DataGrid 渲染得很好,但在 Accordion 内部,所有列的宽度将被压缩为每列 10 像素。不明白为什么。可能是一个错误?

我注意到,如果我将静态宽度设置为 400 而不是“自动”,则列将正确呈现。然后我尝试像您一样将 DataGrid 宽度绑定到 AccordionItem ActualWidth,现在效果很好。谢谢先生!

I'm so glad I stumbled on this! This QA needs to be upvoted. I had a similar problem except with the column widths.

My DataGrid had Width="Auto", along with some *-sized column widths. Outside of the Accordion the DataGrid rendered fine but inside the Accordion, the width of all of the columns would get squished to 10px each. Couldn't figure out why. Could be a bug?

I noticed that if I set a static Width like 400 instead of Auto, the columns would render properly. Then I tried binding the DataGrid Width to the AccordionItem ActualWidth as you did, and it works perfectly now. Thank you sir!

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