Is there any way to alias commands in WPF? -


is there way "alias" commands in wpf ? situation : i've created application uses applicationcommands.delete in context of graphical editor has number of customized canvases. of controls on these canvases use textboxes, here's problem : textbox doesn't respond applicationcommands.delete, responds editorcommands.delete. there way cleanly textbox respond applicationcommands.delete without subclassing or manually setting bindings on every textbox instance ?

to answer specific question, know of no way cause 2 separate routed commands treated same command. because applicationcommands.delete routed command, after delivered target, textbox , there no command binding, begin bubbling up. simplest solution meets requirements install command binding applicationcommands.delete somewhere inbetween textbox way , possibly including window, implements behavior desire.

here's example installs handler on parent grid sends "right" command the focused element in case textbox:

<grid>     <grid.commandbindings>         <commandbinding command="applicationcommands.delete" canexecute="commandbinding_canexecute" executed="commandbinding_executed"/>     </grid.commandbindings>     <dockpanel>         <menu dockpanel.dock="top">             <menuitem header="_edit">                 <menuitem header="_delete" command="applicationcommands.delete"/>             </menuitem>         </menu>         <stackpanel>             <textbox text="some text"/>         </stackpanel>     </dockpanel> </grid> 

and here's code-behind:

private void commandbinding_canexecute(object sender, canexecuteroutedeventargs e) {     e.canexecute = true; }  private void commandbinding_executed(object sender, executedroutedeventargs e) {     editingcommands.delete.execute(null, keyboard.focusedelement); } 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -