Search code examples
c#wpfbackgroundworkerz-orderintptr

Followup: Bring a window to the front in WPF


I'm trying to add a button to my current project that when pressed will send the window to the back for x-seconds, allow the user to work in other windows, and then automatically come to the front again. By combining How to send a WPF window to the back? and Bring a window to the front in WPF, along with a BackgroundWorker, I was able to get this 99% done. When the button is pressed, the window goes to the back, and returns the specified number of seconds later. The problem is that if I go into another window (Opera, Word, etc), it never return from the back. I tried playing with the flags, but can't seem to get it to work. Is this possible to do? And if so, how?

Thanks!


Solution

  • With a hack it's possible. Just do that:

    Topmost = true;
    Topmost = false;
    

    and the window should be in front.