Run Silverlight Prism Command Using Shortcut Keys

Does anyone know if prism can be invoked using a shortcut? I want to say that I want to define the binding of a command to a keyboard shortcut in a declarative way, for example ClientUI :

ClientUI key bindings

Are there open source libraries for this purpose? Or maybe code samples?

I found this question , but I do not think it answers me.

+3
source share
2 answers

I created such a trigger. And I would like to share it with you guys. Basically, it is a System.Windows.Interactivitytrigger that can parse gestures represented as strings. Usage is as simple as in ClientUI:

<UserControl>
    <i:Interaction.Triggers>
        <behaviors:KeystrokeCommandTrigger Command="{Binding SaveChangesCommand}" Gesture="Ctrl+Shift+S" />
        <behaviors:KeystrokeCommandTrigger Command="{Binding RejectChangesCommand}" Gesture="Ctrl+Shift+R" />
        <behaviors:KeystrokeCommandTrigger Command="{Binding NewItemCommand}" Gesture="Ins" />
        <behaviors:KeystrokeCommandTrigger Command="{Binding DeleteSelectedItemCommand}" Gesture="Del" />
        <behaviors:KeystrokeCommandTrigger Command="{Binding UploadSomethingCommand}" Gesture="Ctrl+Shift+U" />
    </i:Interaction.Triggers>
</UserControl>

The code is on pastie .

+3
source

You can write an attached behavior that will listen for the KeyUp event, and then call the command. Complication occurs when translating something like Gesture = "Ctrl + Shift + A". You will need to write a parser to determine exactly which key combination stringrepresents.

+1
source

Source: https://habr.com/ru/post/1756952/


All Articles