How do bring a WPF Window to front?
I have created a single-instance application and want to activate an already opened window if the user starts the app multiple tim开发者_开发知识库es. 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.
精彩评论