So I have a user control within a window that creates a new dialog window when a button is clicked. I would like the window to appear on top of the window calling it. I tried to do this…
NewDialog dlg = new NewDialog();
dlg.WindowStartupLocation = WindowStartupLocation.CenterOwner;
dlg.ShowDialog();
The problem is the owner doesn’t seem to be the calling window (maybe because a user control is making the call and not an actual window?). So I tried adding this…
dlg.Owner = Application.Current.Windows[0];
Which mostly works, but it is not a generic solution as sometimes my new windows have to call a new window, and I want them centered on the calling window, not the primary window. Is there a better way to set the owner correctly to the window the user control it is a part of? I have tried many variations that all seem to have some quirk where the window comes up in a completely different place, or something doesn’t evaluate right and throws an error.
Any suggestions?
If
thisis not of typeWindowuse static Window.GetWindow Method to get the host window.