WPF DataGrid 内部手风琴高度问题
我正在使用最新的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来我最初的想法是正确的 - 我能够解决这个问题的唯一方法是将
DataGrid
的MaxHeight
绑定到ActualHeight
> 的 AccordionItem将以下属性添加到每个
DataGrid
就可以了Looks like my initial idea was right - the only way I have been able to solve this one is to bind the
MaxHeight
of theDataGrid
to theActualHeight
of the AccordionItemAdding the following property to each
DataGrid
did the trick我很高兴我偶然发现了这个!此 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!