WPF 使用切换按钮在区域之间切换
我有一个视图,加载时包含顶部的工具栏和下面的两个区域。
我当前正在使用网格,因此:
- 第 0 行包含工具栏
- ,第 1 行包含区域 1,
- 第 2 行包含区域 2。
工具栏有一个切换按钮,单击该按钮后,将完全隐藏区域 1,并显示区域 2,反之亦然。
实现这一目标的最佳方法是什么?
我尝试绑定 2 行高度以在切换上进行更改,但空间未正确填充。 VerticalAlignment="Stretch"
和 HorizontalAlignment="Stretch"
均被使用。
我还尝试启用和禁用托管该区域的项目控件,但这似乎根本不起作用。
非常感谢任何有关我所做工作的指示! :)
I have a view, that when loaded contains a toolbar at the top, and two regions underneath.
I am currently using a grid, so:
- row 0 contains the toolbar
- row 1 contains region1 and
- row 2 contains region2.
The toolbar has a toggle button, which when clicked, completely hides region1, and shows region 2, and visa-versa.
What is the best way to achieve this?
I have tried binding the 2 rows heights to get altered on the toggle, but the space is not filled correctly. VerticalAlignment="Stretch"
and HorizontalAlignment="Stretch"
are both used.
I have also tried enabling and disabling the itemcontrol hosting the region, but that doesn't seem to work at all.
Any pointers as to what I have done are much appreciated! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定我是否完全理解你想要什么。像这样的东西吗?
Not sure if I fully understand what you want. Something like this?
我也使用了包含region1和region2的这一行。默认情况下,region2 的
Visibility
设置为Collapsed
,当事件发生时(对我来说是一个复选框,数据绑定到 bool 值),我翻转了区域的 Visibility。我的“区域”包含两种不同的布局,并且我没有遇到任何问题。没有代码隐藏的快速示例代码:
I used for this one row that contains region1 and region2 too. region2's
Visibility
set toCollapsed
by default, and when an event occured (a checkbox for me, databound to a bool value) i flipped the Visibility of the regions. My 'regions' contained two different layout, and i don't experienced any issue.A quick sample code without code-behind: