0

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!

Community
  • 1
  • 1
Keven M
  • 972
  • 17
  • 47
  • are wanting the window to show up modally ..? why would you have the window go to the back for a certain amount of time..? is there a reason.. why not set up a boolean that checks the ModalResult once that second window that you had window.bringtofront for example could be checked against.. //from Miscrost site // Show window modally // NOTE: Returns only when window is closed Nullable dialogResult = dialogBox.ShowDialog(); – MethodMan Dec 07 '11 at 16:07
  • The reason for this is that I'm writing this for work, which is in a call center. Our main work window is a java-based web app that they (obnoxiously) have the size restricted on. This means that for my program to be of a usable size, it has to cover some of the information we need. By using this button, it would allow us to hide the program, find the info we need, and then have it pop back in ready to use again. To some degree it's just a "dazzle" feature, but it would be highly useful too, especially not having to minimize/maximize the window from the taskbar. – Keven M Dec 07 '11 at 16:12
  • I was not aware that you were using java / javascript you did not specify that in your initial question.. ok thanks – MethodMan Dec 07 '11 at 16:15
  • No, to clarify I'm using C#. This is a completely separate program from theirs, and I guess what their's is written in doesn't really matter. Mine doesn't interact with theirs at all, it's just a template/shortcut app. – Keven M Dec 07 '11 at 16:22

1 Answers1

0

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

Topmost = true;
Topmost = false;

and the window should be in front.

Fischermaen
  • 12,238
  • 2
  • 39
  • 56
  • So basically get rid of the MoveToForeground and MoveToBackground methods? I'd prefer not to take this approach, but if it ends up being the only way possible I will settle for it. :) – Keven M Dec 07 '11 at 16:08
  • 1
    @KevenM: Forcing a window to be in the foreground is not focused by the windows guidelines. So this here is the one and only, 100 % working workaround. Trust me ;-) – Fischermaen Dec 07 '11 at 16:17
  • How does task manager do it(Rightclicking a running program)? Is it just an exception MS wrote in? And there's no way to tap into that functionality? – Keven M Dec 07 '11 at 16:58
  • @KevenM: I haven't analyzed that. But I think task manager is doing it in that way. Task manager itself can be set to be Topmost. – Fischermaen Dec 07 '11 at 19:50