2

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 Answers 2

1

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;
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.