c# - CommandBindings as static resources in MenuItem -
i doing test commandbindings modifying code found in book , stumbled upon problem.
i'd define custom behaviour cut/copy/paste commands working both usual key combinations , context menu in textbox , standard menu. in order avoid redefining commandbindings declared them window resources. working in textbox don't know how use in menuitems.
this code put in place till now:
<window x:class="myspellchecker.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="myspellchecker" height="331" width="508" windowstartuplocation ="centerscreen" focusable="true"> <window.resources> <commandbinding command="applicationcommands.open" x:key="opencmdbinding" executed="opencmdexecuted" canexecute="opencmdcanexecute"/> <commandbinding command="applicationcommands.save" x:key="savecmdbinding" executed="savecmdexecuted" canexecute="savecmdcanexecute"/> <commandbinding command="applicationcommands.copy" x:key="copycmdbinding" executed="clipboardcmdexecuted" canexecute="clipboardcmdcanexecute"/> <commandbinding command="applicationcommands.cut" x:key="cutcmdbinding" executed="clipboardcmdexecuted" canexecute="clipboardcmdcanexecute"/> <commandbinding command="applicationcommands.paste" x:key="pastecmdbinding" executed="clipboardcmdexecuted" canexecute="clipboardcmdcanexecute"/> </window.resources> <dockpanel> <!--doc menu system on top--> <menu dockpanel.dock ="top" horizontalalignment="left" background="white" borderbrush ="black"> <menuitem header="_file" > <menuitem command ="applicationcommands.open"/> <menuitem command ="applicationcommands.save"/> <separator/> <menuitem header ="_exit" mouseenter ="mouseenterexitarea" mouseleave ="mouseleavearea" click ="fileexit_click"/> </menuitem> <menuitem header="_edit"> <menuitem command ="applicationcommands.copy"/> <menuitem command ="applicationcommands.cut"/> <menuitem command ="applicationcommands.paste"/> </menuitem> <menuitem header="_tools"> <menuitem header ="_spelling hints" mouseenter ="mouseentertoolshintsarea" mouseleave ="mouseleavearea" click ="toolsspellinghints_click"/> </menuitem> </menu> <!-- put toolbar under menu --> <toolbar dockpanel.dock ="top" > <button content ="exit" mouseenter ="mouseenterexitarea" mouseleave ="mouseleavearea" click ="fileexit_click"/> <separator/> <button content ="check" mouseenter ="mouseentertoolshintsarea" mouseleave ="mouseleavearea" click ="toolsspellinghints_click" cursor="help" /> </toolbar> <!-- put statusbar @ bottom --> <statusbar dockpanel.dock ="bottom" background="beige" > <statusbaritem> <textblock name="statbartext" text ="ready"/> </statusbaritem> </statusbar> <grid dockpanel.dock ="left" background ="aliceblue"> <!-- define rows , columns --> <grid.columndefinitions> <columndefinition /> <columndefinition /> </grid.columndefinitions> <gridsplitter grid.column ="0" width ="5" background ="gray" /> <stackpanel grid.column="0" verticalalignment ="stretch" > <label name="lblspellinginstructions" fontsize="14" margin="10,10,0,0">spelling hints</label> <expander name="expanderspelling" header ="try these!" margin="10,10,10,10"> <!-- filled programmatically --> <label name ="lblspellinghints" fontsize ="12"/> </expander> </stackpanel> <!-- area type within --> <textbox grid.column ="1" spellcheck.isenabled ="true" acceptsreturn ="true" name ="txtdata" fontsize ="14" borderbrush ="blue" verticalscrollbarvisibility="auto" horizontalscrollbarvisibility="auto"> <textbox.commandbindings> <staticresource resourcekey="cutcmdbinding"/> <staticresource resourcekey="copycmdbinding"/> <staticresource resourcekey="pastecmdbinding"/> </textbox.commandbindings> </textbox> </grid> </dockpanel>
in situation if wrote in textbox can use cut/copy/paste keyboard shortcuts, context menu , curiously enough main menu. though not working since before write on textbox edit menu items disables and, more that, file menu items never work. work if declare commandbindings in window.commandbindings again i'm trying understand if it's possibile define commands , behaviour once , reuse them through application no matter control using them.
any idea? in advance!
Comments
Post a Comment