In WPF, we often involve the problem of passing parameters between multiple windows, so how do we pass them?
A : in the window's constructor, add the arguments that you want to pass. (If I'm not good at it, see the code below.) )
In the main window, a single button opens a new child window.
The main window class section is as follows: public partial class Mainwindow:window {public MainWindow () { InitializeComponent (); } private void Button_Click (object sender, RoutedEventArgs e) { NewWindow NewWindow = new NewWindow (string str); Newwindow.showdialog (); } }
The child window class is as follows:
public partial class Newwindow:window {public string str{get; set;} Public NewWindow (String strref) { str = strref; InitializeComponent (); } You can refer to the STR variable. }
Note: If we pass the parameter as a value type (int,char,double) , then the data is passed in one direction, that is, from the parent window to the child window only.
Therefore, if you want to implement a parent window that can pass arguments to each other between child windows, then we must do so by passing a variable of the reference type (except for the string type).
As for why, it should be the result of parameter passing at the bottom of the operation. (It may be the same as in c,c++, that is, a copy of the passed parameter is passed through,
I guess. May not be the same as the underlying operation, but at least the appearance is the same. )
WPF multi-window-pass Solution