2
votes

After login I'm opening this Mainwindow

MainWindow window = new MainWindow();

and closing the Login window.

In the main window there is a windows form I'm initializing globally

Scanner form = new Scanner();

I'm hiding and showing this Scanner Winforms according to my need. I need to call a Mainwindow button click from Scanner.cs If I try to do MainWindow window = new MainWindow(); from Scanner.cs it will create a new Mainwindow, which I don't want to do.

These are all the references I found.

2

2 Answers

1
votes

This line of code saved my day

((MainWindow)System.Windows.Application.Current.MainWindow).MainWindow_Btn_Click();

After closing the login I have used this code to set the MainWindow.

Application.Current.MainWindow = window;
0
votes

Create an event in the Scanner like SomethingRequested. In MainWindow subscribe to this event and do what you need.