public static IEnumerable<ActionKeyBinding> From(IEnumerable<IAction> actions) { var converter = new KeyGestureConverter(); return from a in actions where !string.IsNullOrEmpty(a.InputGesture) let g = ParseGesture(a, converter) where g != null select new ActionKeyBinding(a, g); }
/// <summary> /// CanConvertToString() /// </summary> /// <param name="value"></param> /// <param name="context"></param> /// <returns></returns> /// <ExternalAPI/> public override bool CanConvertToString(object value, IValueSerializerContext context) { KeyGesture keyGesture = value as KeyGesture; #pragma warning disable 6506 return((keyGesture != null) && ModifierKeysConverter.IsDefinedModifierKeys(keyGesture.Modifiers) && KeyGestureConverter.IsDefinedKey(keyGesture.Key)); #pragma warning restore 6506 }
/// <summary> /// Initializes a new instance of the ShowAllModulesWindow class. /// </summary> public ShowAllModulesWindow() { this.InitializeComponent(); if (this.AllModulesControl != null && this.AllModulesControl.ShowModuleControl != null) { this.AllModulesControl.ShowModuleControl.Owner = this; } this.SizeChanged += new SizeChangedEventHandler(this.ShowAllModulesWindow_SizeChanged); this.LocationChanged += new System.EventHandler(this.ShowAllModulesWindow_LocationChanged); this.StateChanged += new System.EventHandler(this.ShowAllModulesWindow_StateChanged); this.Loaded += new RoutedEventHandler(this.ShowAllModulesWindow_Loaded); RoutedCommand plusSettings = new RoutedCommand(); KeyGestureConverter keyGestureConverter = new KeyGestureConverter(); try { plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn1Shortcut)); plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn2Shortcut)); plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn3Shortcut)); plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn4Shortcut)); CommandBindings.Add(new CommandBinding(plusSettings, ZoomEventHandlerPlus)); } catch (NotSupportedException) { //localized has a problematic string - going to default plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Add")); plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Plus")); CommandBindings.Add(new CommandBinding(plusSettings, ZoomEventHandlerPlus)); }; RoutedCommand minusSettings = new RoutedCommand(); try { minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut1Shortcut)); minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut2Shortcut)); minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut3Shortcut)); minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut4Shortcut)); CommandBindings.Add(new CommandBinding(minusSettings, ZoomEventHandlerMinus)); } catch (NotSupportedException) { //localized has a problematic string - going to default minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Subtract")); minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Minus")); CommandBindings.Add(new CommandBinding(minusSettings, ZoomEventHandlerMinus)); } }
public void then_input_bindings_keys_mapped_to_commands() { var converter = new KeyGestureConverter(); var commandAndGestures = elementContainer.InputBindings.OfType<InputBinding>() .Select(x => new { x.Command, Gesture = converter.ConvertTo((KeyGesture)x.Gesture, typeof(string)) }); Assert.IsTrue(commandAndGestures.Any(x => policy.Commands.Any(y => y == x.Command && y.KeyGesture == x.Gesture.ToString()))); }
public static IEnumerable<KeyBinding> GenerateKeyBinding(JsonArray array, object obj) { List<KeyBinding> keyBindings = new List<KeyBinding>(); KeyGestureConverter keyGestureConverter = new KeyGestureConverter(); foreach (JsonNode jsonNode in array) { KeyGesture keyGesture = keyGestureConverter.ConvertFromString(jsonNode.GetObjectOrDefault("gesture", "")) as KeyGesture; if (keyGesture == null) continue; MethodInfo methodInfo = obj.GetType().GetMethod(jsonNode.GetObjectOrDefault("command", ""), new Type[0]); if (methodInfo == null) continue; keyBindings.Add(new KeyBinding(new ManualCommand(() => methodInfo.Invoke(obj, null)), keyGesture )); } return keyBindings; }
public static void RaiseMenuItemClickOnKeyGesture(this ItemsControl control, KeyEventArgs args, bool throwOnError) { if (args == null) throw new ArgumentNullException("e"); if (control == null) return; KeyGestureConverter kgc = new KeyGestureConverter(); foreach (var item in control.Items.OfType<MenuItem>()) { if (!string.IsNullOrWhiteSpace(item.InputGestureText)) { KeyGesture gesture = null; if (throwOnError) { gesture = kgc.ConvertFrom(item.InputGestureText) as KeyGesture; } else { try { gesture = kgc.ConvertFrom(item.InputGestureText) as KeyGesture; } catch { } } if (gesture != null && gesture.Matches(null, args)) { item.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent)); args.Handled = true; return; } } RaiseMenuItemClickOnKeyGesture(item, args, throwOnError); if (args.Handled) return; } }
public PreferencesWindow() { InitializeComponent(); converter = new KeyGestureConverter(); }
protected override string ConvertTo(ModifierKeys value, Type type = null) { KeyGestureConverter c = new KeyGestureConverter(); return (string)c.ConvertTo(new KeyGesture(Key.None, value), type ?? typeof(string)); }
protected override ModifierKeys ConvertFrom(string value) { KeyGestureConverter c = new KeyGestureConverter(); return ((KeyGesture)c.ConvertFrom(value)).ModifierKeys; }
public void ConverterTest2() { KeyGesture keyGesture; KeyGestureConverter c = new KeyGestureConverter(); keyGesture = (KeyGesture)c.ConvertFrom(" CTRL + alt + wIN + a"); Assert.AreEqual(ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Windows, keyGesture.ModifierKeys); Assert.AreEqual(Key.A, keyGesture.Key); keyGesture = (KeyGesture)c.ConvertFrom(" CTRL + wIN + f10 + alt"); Assert.AreEqual(ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Windows, keyGesture.ModifierKeys); Assert.AreEqual(Key.F10, keyGesture.Key); keyGesture = (KeyGesture)c.ConvertFrom("Ctrl+Enter"); Assert.AreEqual(ModifierKeys.Control, keyGesture.ModifierKeys); Assert.AreEqual(Key.Enter, keyGesture.Key); Assert.AreEqual("Ctrl+A", c.ConvertTo(new KeyGesture(Key.A, ModifierKeys.Control), typeof(string))); AssertHelper.AssertThrows<NotSupportedException>(() => { c.ConvertFrom(" CTRL + wIN + f10 + alt + b"); }); AssertHelper.AssertThrows<NotSupportedException>(() => { c.ConvertTo(new KeyGesture(Key.A, ModifierKeys.Control), typeof(int)); }); }
// http://www.bryanewert.net/journal/2010/6/8/how-to-use-markupextension-for-a-string-resource-that-define.html /// <summary> /// Initializes a new instance of the <see cref="KeyGestureExtension"/> class. /// </summary> /// <param name="gesture">The gesture.</param> public KeyGestureExtension(string gesture) { var kgc = new KeyGestureConverter(); this.gesture=kgc.ConvertFromString(gesture) as KeyGesture; }
private void CreateKeyBindings(ElementViewModel attachedViewModel) { control.InputBindings.Clear(); var converter = new KeyGestureConverter(); foreach (var command in attachedViewModel.Commands) { if (!string.IsNullOrEmpty(command.KeyGesture)) { control.InputBindings.Add( new InputBinding(command, (KeyGesture)converter.ConvertFrom(command.KeyGesture) ) ); } } }
private void InitKeyboardShortcuts() { gestureConverter = new KeyGestureConverter(); try { var xdoc = XDocument.Load("KeyboardShortcuts.xml"); entries = (from item in xdoc.Descendants("binding") select new ActionBinding { Name = (GestureActionName)Enum.Parse(typeof(GestureActionName), (string)item.Attribute("action")), Gestures = item.Elements("gesture").Select(x => GetGesture(x.Value)).ToArray() } ).ToArray(); } catch { } }
private static KeyGesture ParseGesture(IAction action, KeyGestureConverter converter) { try { return converter.ConvertFromString(action.InputGesture) as KeyGesture; } catch { Logger.Instance.Warn("Unable to create keybinding for action: {0}", action.InputGesture); } return null; }
private void StartWindow(string invocation, string outputModeOptions, AutoResetEvent closedEvent) { this.closedEvent = closedEvent; this.gridViewWindowLoaded = new AutoResetEvent(false); ParameterizedThreadStart threadStart = new ParameterizedThreadStart( new ThreadDelegate(delegate { try { this.gridViewWindow = new Window(); this.managementList = CreateManagementList(outputModeOptions); this.gridViewWindow.Loaded += new RoutedEventHandler(this.GridViewWindowLoaded); this.gridViewWindow.Content = CreateMainGrid(outputModeOptions); this.gridViewWindow.Title = invocation; this.gridViewWindow.Closed += new EventHandler(this.GridViewWindowClosed); RoutedCommand plusSettings = new RoutedCommand(); KeyGestureConverter keyGestureConverter = new KeyGestureConverter(); try { plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn1Shortcut)); plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn2Shortcut)); plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn3Shortcut)); plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn4Shortcut)); this.gridViewWindow.CommandBindings.Add(new CommandBinding(plusSettings, ZoomEventHandlerPlus)); } catch (NotSupportedException) { //localized has a problematic string - going to default plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Add")); plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Plus")); this.gridViewWindow.CommandBindings.Add(new CommandBinding(plusSettings, ZoomEventHandlerPlus)); }; RoutedCommand minusSettings = new RoutedCommand(); try { minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut1Shortcut)); minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut2Shortcut)); minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut3Shortcut)); minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut4Shortcut)); this.gridViewWindow.CommandBindings.Add(new CommandBinding(minusSettings, ZoomEventHandlerMinus)); } catch (NotSupportedException) { //localized has a problematic string - going to default minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Subtract")); minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Minus")); this.gridViewWindow.CommandBindings.Add(new CommandBinding(minusSettings, ZoomEventHandlerMinus)); } this.gridViewWindow.ShowDialog(); } catch (Exception e) { // Store the exception in a local variable that will be checked later. if (e.InnerException != null) { this.exception = e.InnerException; } else { this.exception = e; } } })); guiThread = new Thread(threadStart); guiThread.SetApartmentState(ApartmentState.STA); guiThread.Start(); }
private void FancyExplorer_Loaded(object sender, RoutedEventArgs e) { Application.Current.ShutdownMode = ShutdownMode.OnLastWindowClose; this.Width = System.Windows.SystemParameters.WorkArea.Width; this.Height = System.Windows.SystemParameters.WorkArea.Height * FancyExplorer.Properties.Settings.Default.windowHeightPercent; windowOpenTop = System.Windows.SystemParameters.PrimaryScreenHeight - this.Height; windowClosedTop = System.Windows.SystemParameters.PrimaryScreenHeight; this.Top = windowClosedTop; this.Left = 0; if (!taskbar.AutoHide) { if (taskbar.Position == TaskbarPosition.Left) { this.Left += taskbar.Size.Width; } else if (taskbar.Position == TaskbarPosition.Bottom) { windowOpenTop -= taskbar.Size.Height; } } tabControl.Height = this.Height; tabControl.Width = this.Width; loadTabs(); tabControl.SelectionChanged += delegate(object selSender, SelectionChangedEventArgs selE) { if (tabControl.SelectedIndex == 0) { NewTab(""); } }; try { Timeline.DesiredFrameRateProperty.OverrideMetadata( typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = FancyExplorer.Properties.Settings.Default.animFramerate } ); } catch (Exception ex) { } Duration duration = new Duration(TimeSpan.FromSeconds(FancyExplorer.Properties.Settings.Default.animDuration)); //Window open animation DoubleAnimation topIn = new DoubleAnimation() { Duration = duration, To = windowOpenTop }; DoubleAnimation opacityIn = new DoubleAnimation() { Duration = duration, To = 1 }; PropertyPath pathIn = new PropertyPath("(Window.Top)"); PropertyPath pathInOpacity = new PropertyPath("(Window.Opacity)"); Storyboard.SetTarget(topIn, this); Storyboard.SetTarget(opacityIn, this); Storyboard.SetTargetProperty(topIn, pathIn); Storyboard.SetTargetProperty(opacityIn, pathInOpacity); WindowAnimIn = new Storyboard() { Duration = duration }; WindowAnimIn.Children.Add(topIn); WindowAnimIn.Children.Add(opacityIn); //Window close animation DoubleAnimation topOut = new DoubleAnimation() { Duration = duration, To = windowClosedTop }; DoubleAnimation opacityOut = new DoubleAnimation() { Duration = duration, To = 0 }; PropertyPath pathOut = new PropertyPath("(Window.Top)"); PropertyPath pathOutOpacity = new PropertyPath("(Window.Opacity)"); topOut.To = windowClosedTop; opacityOut.To = 0; Storyboard.SetTarget(topOut, this); Storyboard.SetTarget(opacityOut, this); Storyboard.SetTargetProperty(topOut, pathOut); Storyboard.SetTargetProperty(opacityOut, pathOutOpacity); WindowAnimOut = new Storyboard() { Duration = duration }; WindowAnimOut.Children.Add(topOut); WindowAnimOut.Children.Add(opacityOut); //Make the animations resources Resources.Add("WindowAnimIn", WindowAnimIn); Resources.Add("WindowAnimOut", WindowAnimOut); //Run the window close animation to properly seat the window WindowAnimOut.Begin(); //Configure global hotkey WindowInteropHelper wih = new WindowInteropHelper(this); hWndSource = HwndSource.FromHwnd(wih.Handle); hWndSource.AddHook(GlobalKeyPress); atom = Win32.GlobalAddAtom("GlobalSlideKey"); if (atom == 0) { throw new Win32Exception(Marshal.GetLastWin32Error()); } KeyGestureConverter converter = new KeyGestureConverter(); KeyGesture hotkey = (KeyGesture)converter.ConvertFromInvariantString(FancyExplorer.Properties.Settings.Default.shortcutKeyGesture); uint modifiers = 0; if ((hotkey.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt) { modifiers = modifiers | Win32.MOD_ALT; } if ((hotkey.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { modifiers = modifiers | Win32.MOD_CONTROL; } if ((hotkey.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) { modifiers = modifiers | Win32.MOD_SHIFT; } if ((hotkey.Modifiers & ModifierKeys.Windows) == ModifierKeys.Windows) { modifiers = modifiers | Win32.MOD_WIN; } if (!Win32.RegisterHotKey(wih.Handle, atom, modifiers, (uint)KeyInterop.VirtualKeyFromKey(hotkey.Key))) { throw new Win32Exception(Marshal.GetLastWin32Error()); } //Setup complete windowReady = true; }
// Initialize known object types internal static TypeConverter CreateKnownTypeConverter(Int16 converterId) { TypeConverter o = null; switch (converterId) { case -42: o = new System.Windows.Media.Converters.BoolIListConverter(); break; case -46: o = new System.ComponentModel.BooleanConverter(); break; case -53: o = new System.Windows.Media.BrushConverter(); break; case -61: o = new System.ComponentModel.ByteConverter(); break; case -70: o = new System.ComponentModel.CharConverter(); break; case -71: o = new System.Windows.Media.Converters.CharIListConverter(); break; case -87: o = new System.Windows.Media.ColorConverter(); break; case -94: o = new System.Windows.Input.CommandConverter(); break; case -96: o = new System.Windows.Markup.ComponentResourceKeyConverter(); break; case -111: o = new System.Windows.CornerRadiusConverter(); break; case -114: o = new System.ComponentModel.CultureInfoConverter(); break; case -115: o = new System.Windows.CultureInfoIetfLanguageTagConverter(); break; case -117: o = new System.Windows.Input.CursorConverter(); break; case -124: o = new System.ComponentModel.DateTimeConverter(); break; case -125: o = new System.Windows.Markup.DateTimeConverter2(); break; case -130: o = new System.ComponentModel.DecimalConverter(); break; case -137: o = new System.Windows.Markup.DependencyPropertyConverter(); break; case -138: o = new System.Windows.DialogResultConverter(); break; case -174: o = new System.Windows.Media.DoubleCollectionConverter(); break; case -175: o = new System.ComponentModel.DoubleConverter(); break; case -176: o = new System.Windows.Media.Converters.DoubleIListConverter(); break; case -188: o = new System.Windows.DurationConverter(); break; case -190: o = new System.Windows.DynamicResourceExtensionConverter(); break; case -201: o = new System.Windows.ExpressionConverter(); break; case -204: o = new System.Windows.FigureLengthConverter(); break; case -215: o = new System.Windows.Media.FontFamilyConverter(); break; case -216: o = new System.Windows.FontSizeConverter(); break; case -218: o = new System.Windows.FontStretchConverter(); break; case -220: o = new System.Windows.FontStyleConverter(); break; case -222: o = new System.Windows.FontWeightConverter(); break; case -240: o = new System.Windows.Media.GeometryConverter(); break; case -256: o = new System.Windows.GridLengthConverter(); break; case -267: o = new System.ComponentModel.GuidConverter(); break; case -286: o = new System.Windows.Media.ImageSourceConverter(); break; case -299: o = new System.Windows.Input.InputScopeConverter(); break; case -301: o = new System.Windows.Input.InputScopeNameConverter(); break; case -306: o = new System.ComponentModel.Int16Converter(); break; case -314: o = new System.Windows.Media.Int32CollectionConverter(); break; case -315: o = new System.ComponentModel.Int32Converter(); break; case -319: o = new System.Windows.Int32RectConverter(); break; case -324: o = new System.ComponentModel.Int64Converter(); break; case -338: o = new System.Windows.Input.KeyConverter(); break; case -340: o = new System.Windows.Input.KeyGestureConverter(); break; case -342: o = new System.Windows.KeySplineConverter(); break; case -344: o = new System.Windows.KeyTimeConverter(); break; case -348: o = new System.Windows.LengthConverter(); break; case -387: o = new System.Windows.Media.Media3D.Matrix3DConverter(); break; case -392: o = new System.Windows.Media.MatrixConverter(); break; case -410: o = new System.Windows.Input.ModifierKeysConverter(); break; case -411: o = new System.Windows.Input.MouseActionConverter(); break; case -415: o = new System.Windows.Input.MouseGestureConverter(); break; case -423: o = new System.Windows.NullableBoolConverter(); break; case -445: o = new System.Windows.Media.PathFigureCollectionConverter(); break; case -453: o = new System.Windows.Media.PixelFormatConverter(); break; case -462: o = new System.Windows.Media.Media3D.Point3DCollectionConverter(); break; case -463: o = new System.Windows.Media.Media3D.Point3DConverter(); break; case -467: o = new System.Windows.Media.Media3D.Point4DConverter(); break; case -473: o = new System.Windows.Media.PointCollectionConverter(); break; case -474: o = new System.Windows.PointConverter(); break; case -475: o = new System.Windows.Media.Converters.PointIListConverter(); break; case -492: o = new System.Windows.PropertyPathConverter(); break; case -498: o = new System.Windows.Media.Media3D.QuaternionConverter(); break; case -507: o = new System.Windows.Media.Media3D.Rect3DConverter(); break; case -511: o = new System.Windows.RectConverter(); break; case -521: o = new System.Windows.Media.Animation.RepeatBehaviorConverter(); break; case -538: o = new System.Windows.Markup.RoutedEventConverter(); break; case -545: o = new System.ComponentModel.SByteConverter(); break; case -563: o = new System.ComponentModel.SingleConverter(); break; case -568: o = new System.Windows.Media.Media3D.Size3DConverter(); break; case -572: o = new System.Windows.SizeConverter(); break; case -615: o = new System.ComponentModel.StringConverter(); break; case -619: o = new System.Windows.StrokeCollectionConverter(); break; case -633: o = new System.Windows.TemplateBindingExpressionConverter(); break; case -635: o = new System.Windows.TemplateBindingExtensionConverter(); break; case -637: o = new System.Windows.Markup.TemplateKeyConverter(); break; case -645: o = new System.Windows.TextDecorationCollectionConverter(); break; case -655: o = new System.Windows.ThicknessConverter(); break; case -664: o = new System.ComponentModel.TimeSpanConverter(); break; case -681: o = new System.Windows.Media.TransformConverter(); break; case -692: o = new System.Windows.Markup.TypeTypeConverter(); break; case -696: o = new System.ComponentModel.UInt16Converter(); break; case -698: o = new System.ComponentModel.UInt32Converter(); break; case -700: o = new System.ComponentModel.UInt64Converter(); break; case -701: o = new System.Windows.Media.Converters.UShortIListConverter(); break; case -705: o = new System.UriTypeConverter(); break; case -714: o = new System.Windows.Media.Media3D.Vector3DCollectionConverter(); break; case -715: o = new System.Windows.Media.Media3D.Vector3DConverter(); break; case -722: o = new System.Windows.Media.VectorCollectionConverter(); break; case -723: o = new System.Windows.VectorConverter(); break; case -757: o = new System.Windows.Markup.XmlLanguageConverter(); break; } return o; }
void InitMainMenu() { KeyGestureConverter kgc = new KeyGestureConverter(); 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; if (!string.IsNullOrWhiteSpace(menuItem.InputGestureText)) { this.InputBindings.Add(new InputBinding(menuItem.Command, kgc.ConvertFrom(menuItem.InputGestureText) as InputGesture)); } topLevelMenuItem.Items.Add(menuItem); } } } }