user48408
user48408

Reputation: 3354

Bring modal dialog to front without using TopMost property

I'm using ShowDialog (on a System.Windows.Window) to show a user a confirmation style dialog window. I perform this from a system tray menu option. My problem is that its launching itself hidden behind under windows. If I use TopMost its fine in terms of bringing it to the users attention but using TopMost is too intrusive in other ways. I don't want to force the dialog to always be ontop of other windows.

Before calling ShowDialog I've tried all manner of options such as Focus, Activate, BringIntoView to try bring the dialog to the users attention but to no avail. Have I any other option but to use TopMost? I do want to keep the modal behavior of the dialog.

Upvotes: 0

Views: 2552

Answers (1)

user48408
user48408

Reputation: 3354

The crux of the problem I was having was that setting window.Activate before calling window.ShowDialog had no effect (nor did focus, etc). Instead, before calling ShowDialog I hook up an event handler to the ContentRendered event and activate in then it has the desired effect of bringing the window directly to the front but still allowing users drag other windows over it.

window.ContentRendered += (sender, eventArgs) => window.Activate();
window.ShowDialog();

Upvotes: 1

Related Questions