Exemplo n.º 1
0
        public static void RegisterGlobalHotkeys(this Window window)
        {
            var converter = new KeyConverter();

            foreach (var definition in WindowManager.Definitions.Where(d => d.InputGestureText != null))
            {
                if (definition.InputGestureText.Contains("+"))
                {
                    string[] parts = definition.InputGestureText.Split('+');
                    if (parts.Length == 2)
                    {
                        Type windowViewModelType = definition.ViewModelType;

                        var key = (Key)converter.ConvertFrom(parts[1]);

                        ReactiveCommand <Unit, Unit> openCommand = ReactiveCommand.Create(() =>
                        {
                            windowManager.OpenOrFocusWindow(windowViewModelType);
                        });

                        window.InputBindings.Add(new InputBinding(
                                                     openCommand,
                                                     new KeyGesture(key, ModifierKeys.Control)));
                    }
                    else
                    {
                        throw new ArgumentException("InputGestureText not recognized: " + definition.InputGestureText);
                    }
                }
            }

            window.InputBindings.Add(new InputBinding(windowManager.CreateOpenCommand(typeof(OptionsDialogViewModel), openAsDialog: true), new KeyGesture(Key.F4)));
        }