Example #1
0
        public void Handle(Message <RadRoutedEventArgs> message)
        {
            if (message.Name != "MenuOpening")
            {
                return;
            }
            _menuSource.Clear();
            var list = menuHub.GetMenuItemInfos(new List <string>()
            {
                menuName
            });

            if (list != null)
            {
                _menuSource.AddRange(list);
            }
        }
Example #2
0
        private void InitMenu()
        {
            menuHub = new MenuHub(menuName);
            var menu1 = new MenuItemInfo("菜单1", new RelayCommand(ShowWindow))
            {
                GroupName = "Group1"
            };
            var menu2 = new MenuItemInfo("菜单2", new RelayCommand(ShowWindow))
            {
                GroupName = "Group1"
            };
            var menu3 = new MenuItemInfo("菜单3", new RelayCommand(ShowWindow))
            {
                GroupName = "Group2"
            };
            var menu4 = new MenuItemInfo("菜单4", new RelayCommand(ShowWindow))
            {
                GroupName = "Group2"
            };

            menu1.SubItems.AddRange(new[] { menu2, menu3 });
            //向全局注册菜单
            menuHub.Register(menuName, menu1, 1);
            menuHub.Register(menuName, menu2, 2);
            menuHub.Register(menuName, menu3, 3);
            menuHub.Register(menuName, menu4, 4);
            MenuSource = new ObservableCollection <MenuItemInfo>();//绑定界面的RadContextMenu的菜单集合
            var list = menuHub.GetMenuItemInfos(new List <string>()
            {
                menuName
            });                                                                  //GetMenuItemInfos 为获取合并后的右键菜单

            if (list != null)
            {
                MenuSource.AddRange(list);
            }
        }