This does not work.
gLBxForecastCities.Items.Clear();
dlgForecast dlg = new dlgForecast();
WindowStartupLocation = WindowStartupLocation.CenterOwner;
dlg.ShowDialog();
How do I open a dialog box that opens centered on the current dialog box?
Tahir AnsariPosted Nov 6, 2026, 3:08 PM
One caution about the constructor version:
Owner = Application.Current.MainWindowcenters the new dialog on the application's main window, which isn't always the current dialog. If one dialog opens another, the new dialog won't center on the window that opened it.The first attempt didn't work because
WindowStartupLocationwas set on the calling window instead ofdlg, anddlghad no owner. Without an owner, WPF positions the window as if the setting wereManual.To center on the current dialog, set both properties on the new window from the calling code:
Set them before calling
ShowDialog(). The owner must be a window that has already been shown, sothisworks when the calling dialog is open.Arun PottiPosted Nov 1, 2026, 1:25 AM
Try this,
var dlg = new dlgForecast
{
Owner = this,
WindowStartupLocation = WindowStartupLocation.CenterOwner
};
dlg.ShowDialog();
Clyde EisenbeisPosted Oct 30, 2026, 1:12 PM
This does work:
public dlgForecast(){InitializeComponent();WindowStartupLocation = WindowStartupLocation.CenterOwner;Owner = Application.Current.MainWindow;}//dlgForecast