Button MakeToolbarItem(Lazy <ICommand, IToolbarCommandMetadata> command) { var toolbarButton = new Button { Classes = { "ToolBarItem" }, Command = CommandWrapper.Unwrap(command.Value), Tag = command.Metadata.Tag, Content = new Image { Width = 16, Height = 16, Source = Images.LoadImage(command.Value, command.Metadata.ToolbarIcon) } }; ToolTip.SetTip(toolbarButton, command.Metadata.ToolTip); return(toolbarButton); }
void InitMainMenu() { var mainMenuCommands = App.ExportProvider.GetExports <ICommand, IMainMenuCommandMetadata>("MainMenuCommand"); List <IControl> mainMenuItems = mainMenu.Items.Cast <IControl>().ToList(); foreach (var topLevelMenu in mainMenuCommands.OrderBy(c => c.Metadata.MenuOrder).GroupBy(c => c.Metadata.Menu)) { MenuItem topLevelMenuItem = mainMenu.Items.OfType <MenuItem>().FirstOrDefault(m => (m.Header as string) == topLevelMenu.Key); List <IControl> topLevelMenuItems = topLevelMenuItem?.Items.Cast <IControl>().ToList() ?? new List <IControl>(); foreach (var category in topLevelMenu.GroupBy(c => c.Metadata.MenuCategory)) { if (topLevelMenuItem == null) { topLevelMenuItem = new MenuItem(); topLevelMenuItem.Header = topLevelMenu.Key; mainMenuItems.Add(topLevelMenuItem); } else if (topLevelMenuItems.Count > 0) { topLevelMenuItems.Add(new Separator()); } foreach (var entry in category) { MenuItem menuItem = new MenuItem(); menuItem.Command = CommandWrapper.Unwrap(entry.Value); if (!string.IsNullOrEmpty(entry.Metadata.Header)) { menuItem.Header = entry.Metadata.Header; } if (!string.IsNullOrEmpty(entry.Metadata.MenuIcon)) { menuItem.Icon = new Image { Width = 16, Height = 16, Source = Images.LoadImage(entry.Value, entry.Metadata.MenuIcon) }; } menuItem.IsEnabled = entry.Metadata.IsEnabled; topLevelMenuItems.Add(menuItem); } } topLevelMenuItem.Items = topLevelMenuItems; } mainMenu.Items = mainMenuItems; }
void InitMainMenu() { foreach (var topLevelMenu in mainMenuCommands.OrderBy(c => c.Metadata.MenuOrder).GroupBy(c => c.Metadata.Menu)) { var topLevelMenuItem = mainMenu.Items.OfType <MenuItem>().FirstOrDefault(m => (m.Header as string) == topLevelMenu.Key); foreach (var category in topLevelMenu.GroupBy(c => c.Metadata.MenuCategory)) { if (topLevelMenuItem == null) { topLevelMenuItem = new MenuItem(); topLevelMenuItem.Header = topLevelMenu.Key; mainMenu.Items.Add(topLevelMenuItem); } else if (topLevelMenuItem.Items.Count > 0) { topLevelMenuItem.Items.Add(new Separator()); } foreach (var entry in category) { MenuItem menuItem = new MenuItem(); menuItem.Command = CommandWrapper.Unwrap(entry.Value); if (!string.IsNullOrEmpty(entry.Metadata.Header)) { menuItem.Header = entry.Metadata.Header; } if (!string.IsNullOrEmpty(entry.Metadata.MenuIcon)) { menuItem.Icon = new Image { Width = 16, Height = 16, Source = Images.LoadImage(entry.Value, entry.Metadata.MenuIcon) }; } menuItem.IsEnabled = entry.Metadata.IsEnabled; menuItem.InputGestureText = entry.Metadata.InputGestureText; topLevelMenuItem.Items.Add(menuItem); } } } }