How do I bring to front a WPF Window?

If you are a WinForms, Visual Basic, or basically a programmer from a past generation, then you are wondering where the heck the BringToFront method is. Yes, we could invoke API’s on the window handle (that was the norm when I started programming Windows, DOS was so much easier). Anyway, WPF likes to do things with highly unobvious naming.

So, if you want your WPF window to come to the front, apparently you now Activate it. Yup. I preferred the BringToFront way more.

Anyway, Activate works fine.

var window = new YourWindowClass();

window.Show();

……

//Sometime later it is behind your main app for whatever reason, user put it there, but you now you want it in front.

window.Activate();

 

My use is I have a singleton window that gets shown and hidden, but if it is shown and not in front, I want it brought to front so the user doesn’t get confused.

Simple function, been since Windows could overlay, but in WPF you get a new methodology for invoking it.

 

Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *