WPF 功能区以编程方式折叠和展开
在最新(2010 年 10 月)的 WPF 功能区库中,存在一个用于最小化/最大化(或折叠/展开,如果您愿意)功能区控件的菜单项。
有谁知道是否还有一种方法可以挂钩控制此行为的事件,以便可以从单独的 UI 以编程方式控制它? 或者,更好的是,有没有办法像 2010 Office 应用程序那样在功能区中显示折叠/展开按钮?
With the latest (October 2010) WPF Ribbon libraries, there exists a menu item to minimize/maximize (or collapse/expand, if you prefer) the ribbon control.
Does anyone know if there's also a way to hook into the events that control this behaviour so that it could be controlled programmatically from separate UI?
Or, better yet, is there a way to get a collapse/expand button to display in the ribbon like the 2010 Office apps do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用布尔属性
用于显示/隐藏功能区本身。它是一个依赖属性,因此您可以绑定到它的值以支持您描述的场景。Ribbon
类上的 IsMinimized据我所知,默认模板没有像 Office 那样的显示/隐藏按钮,但修改模板(使用 Blend)来添加一个应该不会太难。
You can use the boolean property
IsMinimized
on theRibbon
class to show/hide the ribbon itself. It is a dependency property, so you can bind to its value to support the scenarios you describe.As far as I know, the default template does not have a show/hide button, like Office does, but it shouldn't be too hard to modify the template (using Blend) to add one.
如果您需要知道栏何时最小化(当您双击选项卡标题时会发生这种情况),您可以挂钩
IsMinimizedChanged
事件,但是呃..它丢失了。希望它是一个 DependencyProperty,这样您就可以通过以下方式成功挂钩任何 DependencyProperty 更改:
DependencyPropertyDescriptor.FromProperty(Ribbon.IsMinimizedProperty, typeof(Ribbon))
.AddValueChanged(ribbon, (o, args) => /* 你的代码在这里 */);
我想做的(因此到达这里)是防止它在双击标题时最小化,所以我最终使用此代码:
DependencyPropertyDescriptor.FromProperty(Ribbon.IsMinimizedProperty, typeof(Ribbon))
.AddValueChanged(ribbon, (o, args) =>ribbon.IsMinimized = false);
不是那么花哨,但完成了工作。
If what you need is know when the bar gets minimized (this happens when you double click a tab header) you could hook to the
IsMinimizedChanged
event, but er.. it is missing.Hopefully it is a
DependencyProperty
so you can successfully hook to anyDependencyProperty
change this way:DependencyPropertyDescriptor.FromProperty(Ribbon.IsMinimizedProperty, typeof(Ribbon))
.AddValueChanged(ribbon, (o, args) => /* your code here */);
What I wanted to do (and hence got here) is to prevent it from minimizing when double clicking the header so I ended up using this code:
DependencyPropertyDescriptor.FromProperty(Ribbon.IsMinimizedProperty, typeof(Ribbon))
.AddValueChanged(ribbon, (o, args) => ribbon.IsMinimized = false);
Is not so fancy but gets the job done.
添加一个切换按钮(简单按钮,根据请求的操作将其内容设置为 v 或 ^),然后您可以在按钮单击中使用 ContentControl 来满足您的要求:
Use contentControl.Visibility = System.Windows.Visibility.Visible;为了最大化功能区
Add a toggle button(simple button and set its content to v or ^ depending upon the operation requested) and then you can use ContentControl in button click to fulfill your requirement:
Use contentControl.Visibility = System.Windows.Visibility.Visible; in order to maximize the ribbon