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?
You could use Window.Activate instead:
window.Activate();
This is the WPF equivelent to calling SetForegroundWindow .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.