Puede simplemente usar las propiedades Window.Left y Window.Top. Léelos desde su ventana principal y asigne los valores (más 20 px o lo que sea) al AboutBox antes de llamando al método ShowDialog()
.
AboutBox dialog = new AboutBox();
dialog.Top = mainWindow.Top + 20;
tenerlo centrado, también puede simplemente utilizar la propiedad WindowStartupLocation. Ponga esto en WindowStartupLocation.CenterOwner
AboutBox dialog = new AboutBox();
dialog.Owner = Application.Current.MainWindow; // We must also set the owner for this to work.
dialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
Si desea que se centra horizontalmente, pero no verticalmente (es decir, fija la ubicación vertical), que tendrá que hacer eso en un manejador de sucesos después de la AboutBox se ha cargado, ya que necesitará para calcule la posición horizontal según el Ancho del AboutBox, y esto solo se conoce después de haber sido cargado.
protected override void OnInitialized(...)
{
this.Left = this.Owner.Left + (this.Owner.Width - this.ActualWidth)/2;
this.Top = this.Owner.Top + 20;
}
gehho.
Gracias gehho. – empo
¿funcionará esto para DataGridCell (dentro de DataGrid wpf4) también? aparentemente no es así – neebz
@nEEbz: ¿Qué quieres decir? ¿Desea mover un 'DataGridCell' relativo a la ventana principal? No entiendo la relación con la pregunta original. Por favor elabora. – gehho