Communication between parent and child windows in wpf

I have a parent window that launches a child window, after the execution of any selection / operation in the child window is closed, and I want to send some information back to the parent window (user class object), which is the best way to execute this in WPF using features provided by WPF?

+5
source share
2 answers

You have many options:

  • You can use a custom event in the child window that the parent window is listening on.
  • You can define a delegate in the child window that references the method in the parent window
  • , ,
  • , VisualTreeHelper
+5

:

, . , . - get set accessor.

(mainWindow) ( , )

, , . , - , case, .

private void btnDelete_Click(object sender, RoutedEventArgs e)
{
    Password passwordentry = new Password();
    passwordentry.ShowDialog();

    if (Application.Current.Properties["PassGate"].ToString() == "mypassword")
    {
        Code, or call to delete the record;
    }
    Application.Current.Properties["PassGate"] = "";
}

() . , PasswordTextBox , Accept Cancel.

private void AcceptButton_Click(object sender, RoutedEventArgs e)
{
    Application.Current.Properties["PassGate"] = PasswordTextBox.Text;
    this.Close();
}
-1

All Articles