How to set Dialog's position that came from .ShowDialog();
to show at the center of the mainWindows.
This is the way I try to set position.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
PresentationSource source = PresentationSource.FromVisual(this);
if (source != null)
{
Left = ??
Top = ??
}
}
You must set a parent window to your window (Owner) and then set the WindowStartupLocation property to "CenterParent"
I found this one the best
XAML:
I think it's easier to use xaml markup
Just in code behind.
For the child window, set at the XAML
To call your child window as a dialog and center of the parent, call it from the parent window, e.g