将 Expander 重置为默认折叠行为
我在 Resizer (ContentControl使用调整大小夹具),并且当控件最初出现时它会正确展开/折叠。 一旦我调整它的大小,扩展器将无法正确折叠,如下所述。 我在我的应用程序上运行了 Snoop,但我没有看到 Expander 或其组成部分设置了任何高度。
我该如何说服 Expander 再次正确崩溃? 或者修改 Resizer 不让 Expander 伤心也可以。
扩展器文档说:
“为使 Expander 正常工作,当 ExpandDirection 属性设置为 Down 或 Up 时,不要在 Expander 控件上指定 Height。同样,当 ExpandDirection 属性设置为 Left 时,不要在 Expander 控件上指定 Width当您在 Expander 控件上设置展开内容的显示方向的大小时,即使窗口折叠,也会显示由大小参数定义的区域。设置展开窗口的大小,设置 Expander 控件的内容或包含该内容的 ScrollViewer 的大小尺寸。”
I'm using an expander inside a Resizer (a ContentControl with a resize gripper), and it expands/collapses properly when the control initially comes up. Once I resize it, the Expander won't properly collapse, as documented below. I ran Snoop on my application, and I don't see any heights set on Expander or its constituents.
How would I go about convincing Expander to collapse properly again? Or modifying Resizer to not make Expander sad would work as well.
Expander documentation says:
"For an Expander to work correctly, do not specify a Height on the Expander control when the ExpandDirection property is set to Down or Up. Similarly, do not specify a Width on the Expander control when the ExpandDirection property is set to Left or Right. When you set a size on the Expander control in the direction that the expanded content is displayed, the area that is defined by the size parameter is displayed with a border around it. This area displays even when the window is collapsed. To set the size of the expanded window, set size dimensions on the content of the Expander control or the ScrollViewer that encloses the content."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通过将 Resizer 移动到 Expander 内解决了这个问题,但我在其他地方遇到了 Expander 问题,所以如果有人有答案,我仍然希望得到答案。
谢谢
I resolved the problem by moving the Resizer inside the Expander, but I've run into the Expander issue elsewhere, so would still like an answer if someone has it.
thanks
从那时起我就没有机会模拟这个特定的问题,但我最近发现将 Height 或 Width 设置为 Double.NaN 会将其重置为默认的自由行为。
讽刺的是,这是通过阅读我最初使用的 Resizer 控件的代码得出的。
I haven't had a chance to mock up this particular issue since then, but I recently discovered that setting Height or Width to Double.NaN resets it to its default free-spirited behavior.
Ironically, this was from reading the code of the Resizer control I was using in the first place.
回答这个问题有点晚了(两年多),但是,嘿,迟到总比不好,对吧?
不管怎样,我遇到了这个确切的问题,并且能够通过一些隐藏代码来保存和重置列宽度来解决它。
我有一个 3 列网格,第一列中有一些内容,第二列中有 GridSplitter,第三列中有扩展器。 看起来发生的情况是,移动 GridSplitter 后,包含 Expander 的列的宽度从“自动”更改为固定大小。 这会导致 Expander 不再按预期折叠。
因此,我添加了一个私有变量和两个事件处理程序:
当 Expander 折叠时,我保存 Column2 的固定宽度(在后台某处自动从 Auto 神奇地更改),然后将宽度重置为 Auto。
然后,当扩展器展开时,我将列恢复到固定宽度,以便它展开到与折叠之前相同的宽度。
这是供参考的 XAML:
Answering this a bit late (2+ years), but, hey, better late than never, right?
Anyway, I ran into this exact problem and was able to solve it with some code-behind to save and reset column widths.
I have a 3 columned Grid, with some content in the first column, the GridSplitter in the second column, and the Expander in the third column. It looks like what is happening is that after the GridSplitter is moved the width of the column containing the Expander is altered from Auto to a fixed size. This causes the Expander to no longer collapse as expected.
So, I added a private variable and two event handlers:
When the Expander is collapsed I save Column2's fixed width (which was altered from Auto auto-magically in the background somewhere) then reset the width to Auto.
Then, when the expander is expanded, I restore the column back to the fixed width so it expands to the same width it was before it was collapsed.
Here's the XAML for reference: