Declaring InputGestures  
Author Message
Thomas S. Andersen





PostPosted: Windows Presentation Foundation (WPF), Declaring InputGestures Top

Some basic c# question:

How do I declare a command witch includes InputGestures. I can’t seem to figure out the c# syntax

public static readonly RoutedUICommand Refresh = new RoutedUICommand("Refresh", "Refresh", typeof(System.Windows.Input.ICommand), );

Best regards,
Thomas Andersen



Visual Studio 200815  
 
 
lee d





PostPosted: Windows Presentation Foundation (WPF), Declaring InputGestures Top

try

public static readonly RoutedUICommand Refresh = new RoutedUICommand("Refresh", "Refresh", typeof(System.Windows.Input.ICommand), new InputGestureCollection[]{new KeyGesture(Key.L, ModifierKeys.Alt),....}

);



 
 
Thomas S. Andersen





PostPosted: Windows Presentation Foundation (WPF), Declaring InputGestures Top

No, that doesn't seems to work.

Cannot implicitly convert type 'System.Windows.Input.KeyGesture' to 'System.Windows.Input.InputGestureCollection' C:\source\...

Argument '4': cannot convert from 'System.Windows.Input.InputGestureCollection[]' to 'System.Windows.Input.InputGestureCollection' C:\source\...


 
 
lee d





PostPosted: Windows Presentation Foundation (WPF), Declaring InputGestures Top

the following seems to compile, did not see if it actually works

KeyGesture CloseCmdKeyGesture = new KeyGesture(Key.L, ModifierKeys.Alt);

InputGestureCollection igc = new InputGestureCollection();

igc.Add(CloseCmdKeyGesture);

RoutedUICommand Refresh = new RoutedUICommand("Refresh", "Refresh", typeof(System.Windows.Input.ICommand), igc);



 
 
Thomas S. Andersen





PostPosted: Windows Presentation Foundation (WPF), Declaring InputGestures Top

Thanks, I was hoping for a oneline declaration.

For the moment I'm using:

public static class WindowCommands
{
public static readonly RoutedUICommand Refresh = new RoutedUICommand("Refresh", "Refresh", typeof(System.Windows.Input.ICommand));

static WindowCommands()
{
Refresh.InputGestures.Add(
new KeyGesture(Key.F5));
}
}

Best regards,
Thomas Andersen


 
 
Thomas S. Andersen





PostPosted: Windows Presentation Foundation (WPF), Declaring InputGestures Top

Ahhh, got it.

Thanks Lee; for pointing me in the right direction.

Here is the correct syntax:
public static readonly RoutedUICommand Refresh = new RoutedUICommand("Refresh", "Refresh", typeof(System.Windows.Input.ICommand), new InputGestureCollection(new InputGesture[] { new KeyGesture(Key.F5) }));

Best regards,
Thomas Andersen