question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyBinding Issue when attaching it to windows with commands with CanExecute methods

See original GitHub issue

If i add for example cal:Message.Attach="[Key Enter] = [EnterPressed]" to the window/page/panel etc and the EnterPressed command had a false CanExecute method it will set IsEnable property for that controller to false and that will disable the window/page/panel and every element in it and if that KeyBinding have more that one combination and they all true but one it will also do the same thing

an example project https://github.com/ahmedflix25/CaliburnMicroKeyBinding

if the CanExecute method is false it should only disable that KeyBinding and nothing else

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Filipsicommented, Aug 26, 2021

Yes, omitting the CanExecute method is the simplest answer. But the problem, in my opinion, is in the usability.

Imagine a scenario where you have some buttons, all of them performing an action with associated CanExecute guard methods so they get automatically disabled. You want all of these actions to also have a keyboard shortcut, so you add keybindings to the container and Attach them to the same actions the buttons are using. Now if any of the buttons gets disabled by their guard method whole container get disabled due to the keybinding.

You can solve this by omitting the CanExecute method and explicitly binding the IsEnabled property for each button. But this defeats the whole concept of using named conventions for automatic action binding that Caliburn.Micro does so well.

Or you can create duplicate methods in the ViewModel for each keybinding that does not have a guard method but does the same logic as the action that the buttons are attached to. But this clutters the ViewModel with multiple new methods and makes the API the ViewModel is providing less clean and harder to use.

These solutions work, but I don’t think any of them is a good solution.

0reactions
KasperSKcommented, Aug 27, 2021

Point taken, I think that an additional property on the ActionMessage is the right choice. I will look into when I have some free time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

wpf - System.Windows.Input.KeyBinding doesn't check ...
Tested using a normal WPF TextBox, and it calls CanExecute once you press Enter. Must indeed be an issue in the 3rd party...
Read more >
Commanding Overview - WPF .NET Framework
A command can indicate whether an action is possible by implementing the CanExecute method. A button can subscribe to the CanExecuteChanged ...
Read more >
CommandBinding.CanExecute Event (System.Windows. ...
Occurs when the command associated with this CommandBinding initiates a check to determine whether the command can be executed on the command target....
Read more >
Using CommandBindings with Actions · Issue #50
Defines a command that implements ICommand and is routed through the element tree. The Execute and CanExecute methods on a RoutedCommand do not ......
Read more >
Understanding Routed Events And Commands In WPF
This article discusses: Event routing and visual trees; Command routing; Avoiding command focus problems; Going beyond routed commands. This article uses the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found