title: Syncing data between two Window in WPF
body: <p>I am developing an application in WPF. I need to load an instance of the Window class (which I call <strong>Win1</strong> here) with which a form is filled. Then, when the Submit button is clicked, <strong>Win1</strong> closes and only then can a new <strong>Win2</strong> window be loaded (another class, also inherited from Window). The problem is that both of them open and I can not synchronize the data obtained from the first <strong>Win1</strong> and pass them to the second <strong>Win2</strong>. I'm just messing up.</p>
  
  <p>Someone can give me a generic idea indicating the tools and the pattern I need to do the above. For the specifications given to me, it is necessary that <strong>Win2</strong> appears only after <strong>Win1</strong> has finished its work.</p>
  
  <p>Even though the application is more complex than I described it now, I would like to post some code, but I manage to confuse the ideas of who is reading me, so I tell you that at the moment I'm managing the windows inside the constructor of App.cs, while <strong>MainWindow.cs</strong> corresponds to <strong>Win2</strong> and I created a new class to implement <strong>Win1</strong>.</p>
  
  <pre><code>public partial class App : Application
  {
     // Params...
  
     public App()
     {
         Client = LoadNetwork();
         User = LoadUser(Client); // Shows Win1
         Games = LoadMinigames();
         mainWindow = new MainWindow(User, Games);
         Application.Current.MainWindow = mainWindow; // On XAML default is Hidden
         mainWindow.Show(); // Shows Win2
     }
  
     // Other methods...
  
  }
  </code></pre>
  
  <p>The biggest problem for me is to pass <strong>User</strong> data to <strong>MainWindow</strong> and I do not have many ideas on how to deal with this case.</p>
  
  <hr>
  
  <blockquote>
    <p>Update</p>
  </blockquote>
  
  <pre><code>public partial class MainWindow : Window
  {
      public UserLoading ul;
      public UserRegistering ur;
      public User.UserProfile User;
      private List&lt;Game.Game&gt; Games;
      public Label Username;
  
      public MainWindow(User.UserProfile user, List&lt;Game.Game&gt; games)
      {
          User = new UserProfile();
          InitializeComponent();
          User = user;
          Games = games;
          Username.Content = User.Username;
  
          DrawList(Games);
      }
  
      //...
  
  }
  </code></pre>
  
  <hr>
  
  <p>I realize I have explained myself a bit 'badly rereading my question several times. So I update it trying to be clearer by reporting here my answer to one of the comments.</p>
  
  <blockquote>
    <p>The UserLoad method is not blocking, because inside it are instantiated classes that inherit Window (other windows for login and registration in other words) then the flow of execution proceeds and instantiates the MainWindow where naturally the argument "user" will result null because the forms have not been filled yet. I realize now that perhaps I had explained myself badly. The call of Win1 is not blocking and I would like it to return only when the user data is ready to be passed as an argument to Win2.</p>
  </blockquote>