tags:

views:

121

answers:

1

I have created a single-instance application and want to activate an already opened window if the user starts the app multiple times. This works fine however I have the problem, that if the already opened window is beyond another applications window, I must bring it to front.

I have tried window.Focus() and window.Show() but both of them seem not to work. As a workaround I use …

bool oldTopMost = window.Topmost;
window.Topmost = true;
window.Topmost = oldTopMost;
window.Focus();

… this does the job but looks to me very ugly. Has anyone a better solution for this?

+3  A: 

You could use Window.Activate instead:

window.Activate();

This is the WPF equivelent to calling SetForegroundWindow.

Reed Copsey
Perfect! Thanks.
HCL