none
Button Hotkeys WITH a Modifier key ? (ALT + [Key])

    Question

  • Is there a way to make Button Hotkeys WITH a Modifier (eg: ALT + [Key]) key with the standard behavior ?

    The fact that default behavior only needs a single key is totally senseless, I juste can't believe it.

    Wednesday, December 22, 2010 11:37 AM

Answers

  • You need to use the InputBinding to do that (applies only to commands), use the Modifier property to achieve that. For example:

    <Window x:Class="CustomCommandTest.CommandWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Custom Command Test" Height="300" Width="300">
    
     <Window.CommandBindings>
      <CommandBinding Command="Help"
        CanExecute="HelpCanExecute"
        Executed="HelpExecuted" />
     </Window.CommandBindings>
    
     <Window.InputBindings>
      <KeyBinding Command="Help" Key="H" Modifiers="Ctrl"/>
      <MouseBinding Command="Help" MouseAction="LeftDoubleClick" />
     </Window.InputBindings>
    
     <Button Command="Help" Content="Help Command Button" />
    </Window>
    Regards

    Yoni

    Wednesday, December 22, 2010 1:16 PM

All replies

  • You need to use the InputBinding to do that (applies only to commands), use the Modifier property to achieve that. For example:

    <Window x:Class="CustomCommandTest.CommandWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Custom Command Test" Height="300" Width="300">
    
     <Window.CommandBindings>
      <CommandBinding Command="Help"
        CanExecute="HelpCanExecute"
        Executed="HelpExecuted" />
     </Window.CommandBindings>
    
     <Window.InputBindings>
      <KeyBinding Command="Help" Key="H" Modifiers="Ctrl"/>
      <MouseBinding Command="Help" MouseAction="LeftDoubleClick" />
     </Window.InputBindings>
    
     <Button Command="Help" Content="Help Command Button" />
    </Window>
    Regards

    Yoni

    Wednesday, December 22, 2010 1:16 PM
  • Hi Alex chez Tesfri,

    Welcome to our forum.

    I think Yoni Horovitz has come up a good solution, have you tried it to resolve your issue.

    Could you tell me the situation of your issue now.

     

    Best regareds,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 27, 2010 7:37 AM
  • Hi, I am sorry for the delay but I afraid the reply alert was considered as spam by my company.

     

    So there is no simple way to manage avoid the default behavior.

    The problem is that makes much more code to add. And then the shortcut key won't be underlined anymore on the corresponding button.

     

    Anyway I suppose I will have to do with it.

    Thanks for reply.

     

    Regards.

    Friday, January 14, 2011 11:11 AM