c# - WPF ComamndBinding Help on MenuItem -
new wpf...was reading wpf routed command bindings per-tab , close getting working.
the menuitem disabled until ruletab (tabitem) selected rather pop find dialog shows system.windows.input.commandbinding on menu. doing wrong?
xaml:
<menuitem header="_find..." isenabled="{binding elementname=ruletab, path=isselected}" > <commandbinding command="find" executed="executefind" canexecute="find_canexecute" ></commandbinding> </menuitem>
code-behind:
private void executefind(object sender, executedroutedeventargs e) { // initiate finddialog finddialog dlg = new finddialog(this.ruletext); // configure dialog box dlg.owner = this; dlg.textfound += new textfoundeventhandler(dlg_textfound); // open dialog box modally dlg.show(); } void dlg_textfound(object sender, eventargs e) { // find dialog box raised event finddialog dlg = (finddialog)sender; // find results , select found text this.ruletext.select(dlg.index, dlg.length); this.ruletext.focus(); } private void find_canexecute(object sender, canexecuteroutedeventargs e) { e.canexecute = ruletab.isselected; }
any suggestions appreciated!
figured out! responded. had move commandbinding to:
<window.commandbindings> <commandbinding command="find" executed="executefind" canexecute="find_canexecute" ></commandbinding> </window.commandbindings>
then reference command=find in menuitem.
you'll find need add commandbinding tabitem (as per linked sample). bind menuitem should use command
property, possibly along commandparameter
, commandtarget
(pointing @ tabitem expect).
for example, have menuitem in contextmenu , want command fire on context (placement target) of contextmenu:
<menuitem header="view" tooltip="open member central view member" command="{x:static local:commands.customerviewed}" commandparameter="{binding path=placementtarget.datacontext, relativesource={relativesource findancestor, ancestortype={x:type contextmenu}}}" commandtarget="{binding path=placementtarget, relativesource={relativesource findancestor, ancestortype={x:type contextmenu}}}" />
Comments
Post a Comment