Wednesday, July 27, 2011

How to Bring Parent Window to Front in WPF application

After you close your child window you always like to have your parent window to present in front of you right away. In Windows Form Applications we can use BringToFront() method to bring your window or control to the front of your screen. How can we do in WFP applications?

There is a easy way to make it happen.

In your parent window set it on focus when the child window is closed. How can we know the child window is closed? Just add a closed even handler to your child window after you introduce it and before you use it.

        private void button1_Click(object sender, RoutedEventArgs e)

        {

            YourChildWindow newChildWindow = new YourChildWindow();

            newChilddWindow.Closed += new EventHandler(newChildWindow_Closed);

            newChildWindow.Show();

        }

 

        void newChildWindow_Closed(object sender, EventArgs e)

        {

            this.Focus();

        }

No comments:

Post a Comment