c# - RegisterClassCommandBinding not firing CanExecute -
in situations (i couldn't found pattern) execution goes over
system.windows.input.commandmanager.invalidaterequerysuggested(); var can = globalcommands.updatewindowtitle.canexecute(title, null); globalcommands.updatewindowtitle.execute(title, null); without entering canexecute nor execute methods. variable "can" false (without executing canexecute), , command never fires. works expected.
this how command created , bound:
var updatetitlebinding = new commandbinding(globalcommands.updatewindowtitle, updatewindowtitle, canupdatewindowtitle); commandmanager.registerclasscommandbinding(typeof(system.windows.window), updatetitlebinding); i can't use
application.current.mainwindow.commandbindings.add( new commandbinding(_addcommand, executeaddcommand, canexecuteaddcommand)); because calling class not visual element , doesn't have commandbindings
i tried calling
system.windows.input.commandmanager.invalidaterequerysuggested(); before canexecute , execute calls, doesn't impact behaviour.
--
do know might happening there? there other patterns use?
the problem looks similar canexecute method going false problem i'm not setting focus anywhere.
thanks!
well since you're passing in null target mean framework route based on keyboard.focusedelement either null (which can happen if application isn't active or keyboard focus within else hwndhost or messagebox) or keyboard.focusedelement non-null not within visual/logicaltree of window.
c# wpf command routed-commands
No comments:
Post a Comment