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 - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -