Devexpress xaf用代码打开菜单(Navigation Item)
第一种:ViewController继承WindowController
public abstract class MyWindowController : WindowController { public MyWindowController() { InitializeComponent(); } protected override void OnActivated() { base.OnActivated(); DevExpress.ExpressApp.SystemModule.ShowNavigationItemController svc = Frame.GetController<DevExpress.ExpressApp.SystemModule.ShowNavigationItemController>(); SingleChoiceAction action = svc.ShowNavigationItemAction; ChoiceActionItem toSelect = action.FindItemByIdPath("菜单路径"); if (toSelect == null) { XtraMessageBox.Show("未找到XX的菜单", GlobalConst.SystemTitle); } else { action.DoExecute(toSelect); } } }
第二种方式:ViewController不继承WindowController
public partial class MyViewController: ViewController { public MyViewController() { InitializeComponent(); } protected override void OnActivated() { base.OnActivated(); DevExpress.ExpressApp.SystemModule.ShowNavigationItemController svc = Application.MainWindow.GetController<DevExpress.ExpressApp.SystemModule.ShowNavigationItemController>(); SingleChoiceAction action = svc.ShowNavigationItemAction; ChoiceActionItem toSelect = action.FindItemByIdPath("菜单路径"); if (toSelect == null) { XtraMessageBox.Show("未找到XX的菜单", GlobalConst.SystemTitle); } else { action.DoExecute(toSelect); } } }
两者的区别就是一个通过Frame获取ShowNavigationItemController对象,另一个通过Application.MainWindow获取ShowNavigationItemController对象。