2
votes

My application is developed using C# (WPF and Prism). It is having 4 projects in it and different regions for each project:

  1. menu region contains menu view
  2. Drawing Region contains drawings
  3. Tree region contains tree view
  4. Status Region contains satus view

I done binding of shortcut keys for menu and it works fine but for that I need to select a menu header first, for example if I want to open new dashBoard window on CTRL+N first i need to select New Menu on the menu bar. If you have a look at other applications like Word, Notepad etc. if you press CTR+N it opens new file and you need not require to go at new menu.

Is it due to different regions in prism?

There is nothing wrong with the code. It is simple input binding code is something like this:

    <UserControl.InputBindings>
        <KeyBinding Key="A"  Command="{Binding AddDashBoardCommand}">   
        </KeyBinding>
    </UserControl.InputBindings>    

Is it due to when I press short keys m in different region n m expecting other region to respond? What is the solution for this?

2

2 Answers

4
votes

Based on my understanding, it may be related to the focus on a particular region. Anyway, a possible solution that would work is by using Windows's InputBindings, instead of defining the ShortKey on a specified Region.

This way, the Input Binding would take action anytime you would have focus on the Window Application, without needing to open the New menu. However, you would need to take into account that the Command Binding would yield on the Shell's ViewModel.

So, if you would need to delegate the action to a particular ViewModel, you could Publish() an Event through EventAggregator, which its type would depend on the action made by the user (NewWindowEvent, CopyEvent, SaveEvent, ...). And therefore, each corresponding ViewModel would then suscribe to the particular Event/s that it would only know how to handle it.

You should be able to use InputBindings with or without Modifiers attribute.

Regards.

1
votes

Please try to use it as below:

<UserControl.InputBindings>
    <KeyBinding Key="A" Modifiers="Control" Command="{Binding AddDashBoardCommand}">   
    </KeyBinding>
</UserControl.InputBindings> 

So, using above (added Modifiers property): shortcut Ctrl+A should work for Add Dashboard command.

BTW, I would recommend changing your Add Dashboard shortcut to Ctrl+D, as Ctrl+A is already used for selecting all text.