I want to a pass local object to the event handler. How can I do that? For example, how can I reference the "graphic" object, which is declared in the main function below, in the event handler function "hyperlinkButton_Click"?
void main()
{
Graphic graphic = new Graphic();
hyperlinkButton.Click+=new RoutedEventHandler(hyperlinkButton_Click);
}
void hyperlinkButton_Click(object sender, EventArgs e)
{
}
Use a delegate or a lambda expression.
hyperlinkButton.Click += (sender, e) => HandleGraphic(graphic, sender, e);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With