February 16, 2010

Show and ShowDialog in WPF

Show a WPF window in modal form use ShowDialog()
private void ShowXXXDialogModal()
{
    // Instantiate the dialog box
    XXXDlg dlg = new XXXDlg();

    // Configure the dialog box
    dlg.Owner = this;
    // Open the dialog box modally 
    dlg.ShowDialog();
}
Show a WPF window in modaless form (ie dont wait for the opened window to close before returning) use Show()
private void ShowXXXDialogModaless()
{
    // Instantiate the dialog box
    XXXDlg dlg = new XXXDlg();

    // Configure the dialog box
    dlg.Owner = this;
    // Open the dialog box modalessly 
    dlg.Show();
}

No comments: