Is it possible (and if so, how can it be achieved?) to pass custom args or sender to a programmatically-defined button in WPF? Say I define a button in the code-behind and I want to specify a custom event args to the Click event of the button, or define a different sender (say, the container for this button), can it be done programmatically?
I would like to achieve something like this:
...
var sender = this;
var args = new CustomEventArgs(sectionName);
var button = new Button();
button.Click += Button_EventHandler_Click(sender, args);
Thanks in advance!
As far as i know you cannot do that as the
Buttonis in charge of creating the event args. You might want to use commands which allow you to pass aCommandParameterwhich then is available in theExecutemethod (which is the counterpart of the click handler).