c# - How to get a MenuItem from within its CanExecute handler? -


how can access related menuitem? has been created on fly, cannot use name in xaml file.

private void menuitem_canexecute(object sender, canexecuteroutedeventargs e) {     var snd = sender; // main window     var orgsource = e.originalsource; // richtextbox;     var src = e.source; // usercontrol      // think must use command, how?     routedcommand routedcommand = e.command routedcommand; } 

you can pass commanding ui element command binding commandparameter property, like

<menuitem ... commandparameter="{binding relativesource={relativesource self}}"/> 

now can access menuitem parameter property of canexecuteroutedeventargs:

private void menuitem_canexecute(object sender, canexecuteroutedeventargs e) {     var menuitem = e.parameter menuitem;     ... } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -