KeyBinding Issue when attaching it to windows with commands with CanExecute methods
See original GitHub issueIf 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:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 andAttach
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 theIsEnabled
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.
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.