How to: Access the Navigation Dock Panel (in a WinForms Application) 如何:访问导航停靠面板(在 WinForms 应用程序中)
This topic describes how to access and customize the Dock Panel used to display Navigation in WinForms applications.
本主题介绍如何访问和自定义用于在 WinForms 应用程序中显示导航的 Dock 面板。
Tip 提示
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T275956
完整的示例项目在 DevExpress 代码示例数据库中可用http://www.devexpress.com/example=T275956
.
- Inherit WindowController in the WinForms module project.
- In the constructor, set the WindowController.TargetWindowType property to Main.
- Override the OnActivated method and subscribe to the Frame.TemplateChanged event.
- In the TemplateChanged event handler, cast Frame.Template to Form and subscribe to the Form.Load event.
- In the Load event handler, cast the template to the INavigationPanelHolder type and access the DockPanel object using the DockPanelNavigation property.
- 在 WinForms 模块项目中继承窗口控制器。
- 在构造函数中,将 WindowController.TargetWindowType 属性设置为 Main。
- 覆盖 On 已激活的方法并订阅 Frame.模板更改事件。
- 在模板更改事件处理程序中,将 Frame.模板转换为窗体并订阅 Form.Load 事件。
- 在 Load 事件处理程序中,将模板强制转换为 I 导航面板所有者类型,并使用 DockPanel 导航属性访问 DockPanel 对象。
The snippet below demonstrates these steps.
下面的代码段演示了这些步骤。
using System.Windows.Forms; using DevExpress.ExpressApp; // ... public class HideNavigationPanelButtonsController : WindowController { public HideNavigationPanelButtonsController() { this.TargetWindowType = WindowType.Main; } protected override void OnActivated() { base.OnActivated(); Frame.TemplateChanged += Frame_TemplateChanged; } private void Frame_TemplateChanged(object sender, EventArgs e) { Form form = (Form)Frame.Template; form.Load += Form_Load; } private void Form_Load(object sender, EventArgs e) { if(Frame.Template is DevExpress.ExpressApp.Win.Templates.INavigationPanelHolder) { DevExpress.XtraBars.Docking.DockPanel navigationPanel = ((DevExpress.ExpressApp.Win.Templates.INavigationPanelHolder)Frame.Template).DockPanelNavigation; navigationPanel.Options.ShowAutoHideButton = false; navigationPanel.Options.ShowCloseButton = false; } } protected override void OnDeactivated() { Frame.TemplateChanged -= Frame_TemplateChanged; base.OnDeactivated(); } }
In the code above, the BaseDockOptions.ShowAutoHideButton and BaseDockOptions.ShowCloseButton options are changed. You can use other properties of the DockPanelOptions as well.
在上面的代码中,baseDockOptions.ShowAutoHide按钮和BaseDockOptions.显示关闭按钮选项被更改。您也可以使用 DockPanelOptions 的其他属性。
Important 重要
You can access the DockPanel object directly in the TemplateChanged event handler, but your settings will be overriden by XAF defaults in this instance. So, use the Form.Loadevent to override defaults.
您可以在 TemplateChanged 事件处理程序中直接访问 DockPanel 对象,但在此实例中,XAF 默认值将覆盖您的设置。因此,使用 Form.Loadevent 覆盖默认值。
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客户端