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++: Boost interprocess memory mapped file error -

python - IO.UnsupportedOperation: Not Writable -

python - Selecting distinct values from a column in Peewee -