示例#1
0
 // Register CommandBinding for all windows.
 private void RegisterCommand(GestureCommand command, ExecutedRoutedEventHandler commandFunction, CanExecuteRoutedEventHandler CanDoCommand)
 {
     CommandManager.RegisterClassCommandBinding
     (
         typeof(Window),
         new CommandBinding(command, commandFunction, CanDoCommand)
     );
 }
示例#2
0
        public App()
        {
            // Static binding for buttons in general view
            List <CommandBinding> binding = new List <CommandBinding>();

            binding.Add(new CommandBinding(StaticCommands.IncreaseSoundCommand, IncreaseSound, CanIncreaseSound));
            binding.Add(new CommandBinding(StaticCommands.DecreaseSoundCommand, DecreaseSound, CanDecreaseSound));
            binding.Add(new CommandBinding(StaticCommands.MuteSoundCommand, MuteSound, CanMuteSound));
            binding.Add(new CommandBinding(StaticCommands.EnableVoiceControlCommand, EnableVoiceControl, CanEnableVoiceControl));
            binding.Add(new CommandBinding(StaticCommands.DisableVoiceControlCommand, DisableVoiceControl, CanDisableVoiceControl));

            foreach (var item in binding)
            {
                CommandManager.RegisterClassCommandBinding(typeof(Window), item);
            }

            // Default application level key bindings
            CommandDescriptions.Add(new CommandDescription(CommandType.IncreaseVolume, "Increase Volume", Key.Up, ModifierKeys.Control));
            CommandDescriptions.Add(new CommandDescription(CommandType.DecreaseVolume, "Decrease Volume", Key.Down, ModifierKeys.Control));
            CommandDescriptions.Add(new CommandDescription(CommandType.MuteSound, "Mute sound", Key.M, ModifierKeys.Control));
            CommandDescriptions.Add(new CommandDescription(CommandType.EnableVoiceControl, "Enables voice control", Key.E, ModifierKeys.Control));
            CommandDescriptions.Add(new CommandDescription(CommandType.DisableVoiceControl, "Disables voice control", Key.D, ModifierKeys.Control));

            foreach (var commandDescription in this.CommandDescriptions)
            {
                var command = new GestureCommand(commandDescription);
                this.Commands.Add(command);

                switch (commandDescription.Type)
                {
                case CommandType.IncreaseVolume:
                    RegisterCommand(command, IncreaseSound, CanIncreaseSound);
                    break;

                case CommandType.DecreaseVolume:
                    RegisterCommand(command, DecreaseSound, CanDecreaseSound);
                    break;

                case CommandType.MuteSound:
                    RegisterCommand(command, MuteSound, CanMuteSound);
                    break;

                case CommandType.EnableVoiceControl:
                    RegisterCommand(command, EnableVoiceControl, CanEnableVoiceControl);
                    break;

                case CommandType.DisableVoiceControl:
                    RegisterCommand(command, DisableVoiceControl, CanDisableVoiceControl);
                    break;

                default:
                    break;
                }
            }
        }
示例#3
0
        private KeyBinding createKeyBinding(GestureCommand command)
        {
            var keyboardBinding = new KeyBinding();

            keyboardBinding.Command = command;

            Binding keyBinding = new Binding("Key");

            keyBinding.Source = command.CommandDescription;
            keyBinding.Mode   = BindingMode.OneWay;
            keyBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            BindingOperations.SetBinding(keyboardBinding, KeyBinding.KeyProperty, keyBinding);


            Binding modifiersBinding = new Binding("ModifierKeys");

            modifiersBinding.Source = command.CommandDescription;
            modifiersBinding.Mode   = BindingMode.OneWay;
            modifiersBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            BindingOperations.SetBinding(keyboardBinding, KeyBinding.ModifiersProperty, modifiersBinding);

            return(keyboardBinding);
        }