title: Unable to add a new row to the observablecollection listbox?
body: <p>In my project I have the following pages:</p>
  <blockquote>
  <p>Mainwindow.xaml</p>
  <p>Window1.xaml</p>
  <p>User.cs</p>
  <p>App.xaml</p>
  </blockquote>
  <p>I declared the <code>Name</code> and <code>Age</code> property in <code>User.cs</code> and on <code>MainWindow.xaml</code> I made a <code>ObservableCollection</code> for a <code>ListBox</code>. <code>MainWindow</code> has a <code>Button Add</code>. When we click on the <code>Add button</code>. Then the <code>Window1.xaml</code> form is displayed. Which has two <code>TextBoxes</code> of name and age and a button (<code>ADD Name</code>). Now I want when we click on the <code>Add Name button</code> then the details in the both text boxes are attached to the <code>ObservableCollection</code> that is defined on the <code>Mainwindow.xaml.cs</code>.</p>
  <p>Please suggest me want can I do:</p>
  <pre><code>public partial class Window1 : Window
  {
      
      public Window1()
      {
          InitializeComponent();
      }
  
      private void OnInit(object sender, RoutedEventArgs e)
      {
          string textA=textBox1.Text;
          int textB=Convert.ToInt32(textBox2.Text);
          this.DataContext = new User(textA, textB);
      }
  
      private void button1_Click(object sender, RoutedEventArgs e)
      {
          User user = (User)(this.DataContext);
          new MainWindow().observableCollection.Add(user);
          this.Close();
      }
  }
  </code></pre>
  <p>now I ran this code  I am unable to get the values in the user object.</p>