public static void RegisterHotKey(RadMenuItem menuItem) { if (!string.IsNullOrEmpty(menuItem.InputGestureText) && menuItem.Command != null && menuItem.IsEnabled) { var helper = new KeyGestureValueSerializer(); if (helper.CanConvertFromString(menuItem.InputGestureText, null)) { var inputGesture = helper.ConvertFromString(menuItem.InputGestureText, null) as KeyGesture; if (inputGesture != null) { var binding = new KeyBinding(menuItem.Command, inputGesture); binding.CommandParameter = menuItem.CommandParameter; Application.Current.MainWindow.InputBindings.Add(binding); } } } }
public SettingViewModel() { _screenService = new ScreenService(); var kgvs = new KeyGestureValueSerializer(); if (kgvs.ConvertFromString(Properties.Settings.Default.ShortcutKey, null) is KeyGesture kg) { HotKey = new HotKey(kg.Key, kg.Modifiers); } else { HotKey = new HotKey(Key.E, ModifierKeys.Control); } PictureDir = Properties.Settings.Default.PicDir; IsNotifyWhenSuccess = Properties.Settings.Default.IsNotifyWhenSuccess; UpdateDisplayItems(); }