C# - Return variable from child window to parent window in WPF

前端 未结 3 1661
滥情空心
滥情空心 2020-12-16 23:45

I have a main window called form1. in form1 I have a button, when it is pressed it will open form2 (form2.ShowDialog()). In form2 I have a button called \"Check\". When the

3条回答
  •  清酒与你
    2020-12-17 00:23

    This answer while not perfectly on target will be more useful to people that google themselves here for the general solution of how to communicate between windows:

    There is no reason at all to set up events to access objects of the Main Window of you application. You can simply call them on the popup code and be done with it:

    ((MainWindow)Application.Current.MainWindow).textBox1.Text = "Some text";
    

提交回复
热议问题