D
D
Denis Mashanov2016-07-25 18:37:21
XAML
Denis Mashanov, 2016-07-25 18:37:21

How to call a function that determines the focus for a Window?

Help please, I can not solve the issue with the Focus () function in the main Window.
The matter is that I have 2 Window (Windows). Window1 is the main form from which Window2 is launched. To set the focus of Window2, I can use code like this in Window1.

Window2 open = new Window2();
open.Focus();

And how can I set the focus for Window1 from Window2?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sanostee, 2016-07-25
@LoneRay

You can pass a reference to an instance of Window1 to the Window2 constructor. For example, like this:

private readonly Window1 window1;

public Window2(Window1 window1)
{
  InitializeComponent();
  this.window1 = window1;
}

Create an instance of Window2 (if the creation occurs in Window1):
And after that set the focus for window1
-----------
Otherwise, you can dig into the collection of all application windows through the Application.Current.Windows property

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question