0

Is it possible to register an application command in Catel which would fire only when specific control has a focus?

For example, in the Catel.Examples.WPF.Commanding example, (https://github.com/Catel/Catel.Examples/tree/master/src/NET/Catel.Examples.WPF.Commanding) if I replace TextBlock with TextBox and add RibbonButtons with ApplicationCOmmands.Cut and ApplicationCommands.Paste, these Application commands work only on focused TextBox.

Is it possible to make Refresh command execute only on the DocumentView which has a focus?

Alternatively, is there an example or guidance on using RoutedUICommands with Catel and its ICommandManager?

Thanks, Tom

1 Answers1

0

This is possible if you register an empty app-wide command. Then you can add an action / subcommand whenever you initialize a view model and unregister when the vm is closed again. This way, the command will be invoked against all "open" instances (and only be executable if one or more subcommands are available).

Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32
  • Hm, I don't understand... In the Commanding example there are 4 DocumentViewViewModels initialized and active at the same time, so they all execute Refresh command. I'd like to refresh only one of them, the one which has focus (I replaced TextBlock with TextBox, which is closer to my actual problem). I can make it work with Routed commands and System.Windows.Input.CommandManager instead of IComandManager, but I'd rather not mix the two if possible. I looked at Catel, LogViewer, Orchestra for a similar example, but couldn't find any. Could you post a modified Commanding example somewhere? Thx. –  Dec 31 '16 at 13:52
  • Then you need to unregister the commands manually on SelectedTabChanged. – Geert van Horrik Jan 03 '17 at 09:01