How to: Access the Navigation Control 如何:访问导航控件
This example shows how to access and customize the navigation control. Since customizations will affect only the user interface and will not depend on the current View or data, a Window Controller needs to be created. For detailed information on the navigation system, refer to the Navigation System topic.
此示例演示如何访问和自定义导航控件。由于自定义将仅影响用户界面,并且不依赖于当前视图或数据,因此需要创建一个窗口控制器。有关导航系统的详细信息,请参阅导航系统主题。
Tip 提示
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E240
完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=E240
.
WinForms Controller
WinForms 控制器
Add a new Window Controller to the WinForms module project and override its protected OnActivated method, subscribe to the ActionBase.CustomizeControl event and perform the required customizations in the event handler.
向 WinForms 模块项目添加新的窗口控制器,并重写其受保护的 OnActivated 方法,订阅 ActionBase.CustomizeControl 事件并在事件处理程序中执行所需的自定义。
using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.SystemModule; using DevExpress.XtraBars.Navigation; using DevExpress.XtraNavBar; using DevExpress.XtraTreeList; // ... public class WinCustomizeNavigationController : WindowController { public WinCustomizeNavigationController() { TargetWindowType = WindowType.Main; } protected override void OnActivated() { base.OnActivated(); Frame.GetController<ShowNavigationItemController>().ShowNavigationItemAction.CustomizeControl += ShowNavigationItemAction_CustomizeControl; } private TreeList GetEmbeddedTreeList(NavBarGroupControlContainer container) { if(container != null && container.Controls.Count == 1) { return container.Controls[0] as TreeList; } return null; } private void CustomizeEmbeddedTreeList(NavGroupCollection groups) { foreach(NavBarGroup group in groups) { TreeList treeList = GetEmbeddedTreeList(group.ControlContainer); // Customize TreeList in old templates and new templates with UseLightStyle set to false } } private void ShowNavigationItemAction_CustomizeControl(object sender, CustomizeControlEventArgs e) { if(e.Control is AccordionControl) { // Customize AccordionControl } else if(e.Control is NavBarControl) { // Customize NavBarControl CustomizeEmbeddedTreeList(((NavBarControl)e.Control).Groups); } else if(e.Control is TreeList) { // Customize TreeList } } protected override void OnDeactivated() { Frame.GetController<ShowNavigationItemController>().ShowNavigationItemAction.CustomizeControl -= ShowNavigationItemAction_CustomizeControl; base.OnDeactivated(); } }
ASP.NET Controller
ASP.NET控制器
Add a new Window Controller to the ASP.NET module project and override its protected OnActivated method to access the current Controller.Frame. Subscribe to the ActionBase.CustomizeControl event and perform the required customizations in the event handler.
向ASP.NET模块项目添加新的窗口控制器,并重写其受保护的 OnActivated 方法以访问当前控制器。订阅 ActionBase.自定义控制事件,并在事件处理程序中执行所需的自定义。
Note 注意
The CustomizeControl event cannot be raised if the navigation optimization is enabled (the WebApplication.OptimizationSettings.EnableNavigationControlDelayedCreation property is set to true), because the Navigation Control is not recreated through the callback.
如果启用了导航优化(Web应用程序.优化设置.启用导航控制延迟创建属性设置为 true),则无法引发"自定义控制"事件,因为导航控件不会通过回调。
using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.SystemModule; using DevExpress.ExpressApp.Web.Templates.ActionContainers; using DevExpress.Web; //... public class WebCustomizeNavBarController : WindowController { public WebCustomizeNavBarController() { TargetWindowType = WindowType.Main; } protected override void OnActivated() { base.OnActivated(); Frame.GetController<ShowNavigationItemController>().ShowNavigationItemAction.CustomizeControl += ShowNavigationItemAction_CustomizeControl; } private void ShowNavigationItemAction_CustomizeControl(object sender, CustomizeControlEventArgs e) { ASPxNavBar navBar = e.Control as ASPxNavBar; if(navBar != null) { // Customize the main ASPxNavBar control. navBar.EnableAnimation = true; foreach(NavBarGroup group in navBar.Groups) { foreach(NavBarItem item in group.Items) { if(item is NavBarTreeViewItem) { ASPxTreeView innerTreeView = ((NavBarTreeViewItem)item).TreeViewNavigationControl.Control; // Customize the inner ASPxTreeView control inside the navigation group. innerTreeView.ShowExpandButtons = false; } } } } else { ASPxTreeView mainTreeView = e.Control as ASPxTreeView; if(mainTreeView != null) { // Customize the main ASPxTreeView control. mainTreeView.ShowExpandButtons = false; } } } protected override void OnDeactivated() { base.OnDeactivated(); Frame.GetController<ShowNavigationItemController>().ShowNavigationItemAction.CustomizeControl -= ShowNavigationItemAction_CustomizeControl; } }
Mobile Controller
Mobile控制器
Add a new Window Controller to the Mobile module project and override its protected OnActivated method, subscribe to the ActionBase.CustomizeControl event and perform the required customizations in the event handler.
向移动模块项目添加新的窗口控制器并重写其受保护的 OnActivated 方法,订阅 ActionBase.CustomizeControl 事件并在事件处理程序中执行所需的自定义。
using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.Mobile.MobileModel; using DevExpress.ExpressApp.SystemModule; // ... public class MobileCustomizeNavigationController : WindowController { public MobileCustomizeNavigationController() { TargetWindowType = WindowType.Main; } protected override void OnActivated() { base.OnActivated(); Frame.GetController<ShowNavigationItemController>().ShowNavigationItemAction.CustomizeControl += ShowNavigationItemAction_CustomizeControl; } private void ShowNavigationItemAction_CustomizeControl(object sender, CustomizeControlEventArgs e) { Navigation navigation = e.Control as Navigation; foreach (Command command in navigation.Items) { // Customize navigation items } } protected override void OnDeactivated() { Frame.GetController<ShowNavigationItemController>().ShowNavigationItemAction.CustomizeControl -= ShowNavigationItemAction_CustomizeControl; base.OnDeactivated(); } }
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客户端