I have encountered an error called System.InvalidOperationException.
Additional information: Specified element is already the logical child of another element. Disconnect it first.
I have searched through internet for the solutions but none of them solve my problem.
I created a button called "Open Dialog", to open a dialog. After I opened the dialog, there are two buttons showed in the dialog, "Save" and "Cancel". The function of "Cancel" is to close the dialog. However, after I clicked "Cancel", when I tried to reopen the dialog again by clicking the "Open Dialog", I have encountered the error stated above.
I will post my codes here as well for the event handling method.
In the class of MainWindow:
private void openDialogButton_Click(object sender, RoutedEventArgs e)
{
PersonIDTable.ShowDialog();
}
In the ViewModel:
public void ShowDialog()
{
PersonID.UserControls.PersonIDDialog dialog = new PersonID.UserControls.PersonIDDialog (this);
dialog.Show();
}
In the class of Dialog:
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
Do you guys have any idea to solve the problem? Your help will be much appreciated.