zoukankan      html  css  js  c++  java
  • 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();
        }
    }
  • 相关阅读:
    面试
    vue axios 应用
    3D全景之ThreeJs
    css垂直居中
    事件处理过程中遇到的问题
    文字溢出
    jquery: 偏移量计算
    jquery: sand picture
    jquery: update carousel logic & animate
    jquery: carousel arrow click
  • 原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Access-the-Navigation-Control.html
Copyright © 2011-2022 走看看