I have a Window which pop-ups another Window. I want the second Window to be able to return an object to the first Window when a button is pressed. How would I do this?
Holy mother of Mars, this took me forever to figure out:
WINDOW 1:
if ((bool)window.ShowDialog() == true)
{
Window2 content = window.Content as Window2;
string result = content.result;
int i = 0;
}
WINDOW 2:
public partial class Window2 : UserControl
{
public string result
{
get { return resultTextBox.Text; }
}
public Window2()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Window.GetWindow(this).DialogResult = true;
Window.GetWindow(this).Close();
}
}
XAML: