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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -