How to: Access the Office Navigation Bar 如何:访问Office导航栏
This topic demonstrates how to access the Office Navigation Bar used to show the navigation root groups when the OutlookStyleMainRibbonForm Template is used in a WinForms application.
本主题演示如何在 WinForms 应用程序中使用 OutlookStyleMainRibbon窗体模板时访问用于显示导航根组的 Office 导航栏。
Tip 提示
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T392480
完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=T392480
Perform the following steps to access the OfficeNavigationBar object and customize its settings.
Create a new WindowController in your WinForms module.
2.The OfficeNavigationBar control is located on the OutlookStyleMainRibbonFormTemplate (see IModelRootGroupsStyle.RootGroupsStyle). To access this Template after it has been created or changed, override the Controller's OnActivated method and subscribe to the Frame.TemplateChanged event of the main Window.
3.In the TemplateChanged event handler, cast the Frame.Template property to the Form type and handle the Form.Load event.
4.In the Form.Load event handler, cast the sender to the IOfficeNavigationBarHolder type.
5.To access the OfficeNavigationBar object, use the IOfficeNavigationBarHolder.OfficeNavigationBar property. For instance, you can set the OfficeNavigationBar.MaxItemCount property to 4 to change the maximum number of items simultaneously displayed within the OfficeNavigationBar control.
6.Unsubscribe from the TemplateChanged event in the overridden OnDeactivated method when the Controller is deactivated.
执行以下步骤以访问 Office 导航栏对象并自定义其设置。
1.在 WinForms 模块中创建新的窗口控制器。
2.Office导航栏控件位于 OutlookStyleMainRibbon窗体模板上(请参阅 ImodelrootGroupsStyle.rootGroups 样式)。要在创建或更改此模板后访问此模板,请重写控制器的 OnActivated 方法并订阅主窗口的 Frame.templateChanged 事件。
3.In模板更改事件处理程序,将 Frame.Template 属性转换为窗体类型并处理 Form.Load 事件。
4.In Form.Load 事件处理程序,将发送方转换为 IOffice 导航栏类型。
5.To访问 Office 导航栏对象时,请使用 IOffice 导航栏。例如,您可以将 Office 导航栏.MaxItemCount 属性设置为 4,以更改 Office 导航栏控件中同时显示的最大项目数。
6.在控制器停用时,取消订阅重写的 On 停用方法中的模板更改事件。
using DevExpress.ExpressApp.Win.Templates; using DevExpress.XtraBars.Ribbon; //... public class OfficeNavigationBarCustomizationController : WindowController { private void Frame_TemplateChanged(object sender, EventArgs e) { Form form = Frame.Template as Form; if(form != null) { form.Load += Form_Load; } } private void Form_Load(object sender, EventArgs e) { IOfficeNavigationBarHolder officeNavigationBarHolder = sender as IOfficeNavigationBarHolder; if(officeNavigationBarHolder != null) { officeNavigationBarHolder.OfficeNavigationBar.MaxItemCount = 4; } } protected override void OnActivated() { base.OnActivated(); Frame.TemplateChanged += Frame_TemplateChanged; } protected override void OnDeactivated() { Frame.TemplateChanged -= Frame_TemplateChanged; base.OnDeactivated(); } public OfficeNavigationBarCustomizationController() { TargetWindowType = WindowType.Main; } }
Run the application to ensure that the maximum number of visible OfficeNavigationBar items is 4.
运行应用程序以确保可见 Office 导航栏项目的最大数量为 4。
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端