I'm trying to add an event handler to Click event
Button btn = new Button();
btn.Height = 40;
btn.Width = 120;
btn.Click += new RoutedEventHandler(ShowRes);
mainPanel.Children.Add(btn);
It only works when method ShowRes()
is static, but I need it to be non-static to change textBoxes in my wpf window by this method.
When I'm trying to add non-static method it throws an exception An object reference is required for the non-static field, method, or property "MainWindow.ShowRes(object, RoutedEventArgs)"
private void ShowRes(object sender, RoutedEventArgs e)
How can I achieve it?