EPR类企业管理系统

在我们现有系统基础上或全新开发,提供定制服务
为您的企业高效快速实施ERP,WMS,MES,CRM管理系统
全面管控物料仓库、销售业务、采购业务、仓库业务
生产过程、质量检验、组织架构、业务报表


定制
QQ:460-3528

开发
QQ群:3360-90194

源码
微信:136-3650-3721

如何:访问导航控件

本示例说明如何访问和自定义导航控件。由于自定义将仅影响用户界面,并且不依赖于当前的View或数据,因此需要创建一个Window Controller。有关导航系统的详细信息,请参阅导航系统主题。

提示

DevExpress代码示例数据库(http://www.devexpress.com/example=E240)中提供了完整的示例项目。

WinForms控制器

将新的Window Controller添加到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控制器

将新的Window Controller添加到ASP.NET模块项目中,并覆盖其受保护的OnActivated方法以访问当前的Controller.Frame。订阅ActionBase.CustomizeControl事件,然后在事件处理程序中执行所需的自定义。

注意

CustomizeControl事件不能如果启用导航优化(募集WebApplication.OptimizationSettings.EnableNavigationControlDelayedCreation属性设置为),因为导航控制不通过回调重新创建。

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;
    }
}

移动控制器

将新的Window Controller添加到Mobile模块项目中,并覆盖其受保护的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();
    }
}
相关文章

转载保留此链接,注明出处