arti
arti

Reputation: 657

How to launch method when window got focus again in WPF?

My app is multi-window, here is quickly how it works:

In main window I have a list of items, when I click on one, it opens another window where I can modify it. When I close that window, I want main window to refresh its content. I've tried many event handlers including GotFocus() but it doesn't want to launch my method to refresh the list. Any advise?

Upvotes: 1

Views: 458

Answers (1)

Mikael Nitell
Mikael Nitell

Reputation: 1129

If you want something to happen when the other window is closed, you can subscribe to its closed event. This will fire when the windows is closed.

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        var wnd = new Window1();
        wnd.Closed += wnd_Closed;
        wnd.Show();
    }

    void wnd_Closed(object sender, EventArgs e)
    {
        MessageBox.Show("Closed");
    }

Upvotes: 3

Related Questions