WPF 功能区以编程方式折叠和展开

发布于 2024-10-21 00:43:31 字数 176 浏览 6 评论 0原文

在最新(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 技术交流群。

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

发布评论

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

评论(3

半世晨晓 2024-10-28 00:43:31

您可以使用布尔属性 Ribbon 类上的 IsMinimized 用于显示/隐藏功能区本身。它是一个依赖属性,因此您可以绑定到它的值以支持您描述的场景。

据我所知,默认模板没有像 Office 那样的显示/隐藏按钮,但修改模板(使用 Blend)来添加一个应该不会太难。

You can use the boolean property IsMinimized on the Ribbon 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.

吃兔兔 2024-10-28 00:43:31

如果您需要知道栏何时最小化(当您双击选项卡标题时会发生这种情况),您可以挂钩 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 any DependencyProperty 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.

好听的两个字的网名 2024-10-28 00:43:31

添加一个切换按钮(简单按钮,根据请求的操作将其内容设置为 v 或 ^),然后您可以在按钮单击中使用 ContentControl 来满足您的要求:

     ContentControl contentControl = FindVisualChildataBankyName<ContentControl>(rbnName, "mainItemsPresenterHost");
     contentControl.Visibility = System.Windows.Visibility.Collapsed;

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:

     ContentControl contentControl = FindVisualChildataBankyName<ContentControl>(rbnName, "mainItemsPresenterHost");
     contentControl.Visibility = System.Windows.Visibility.Collapsed;

Use contentControl.Visibility = System.Windows.Visibility.Visible; in order to maximize the ribbon

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