title: Binding object to window textboxes in WPF
body: <p>I have a class named <code>Data</code> with some public members: <code>Name</code>, <code>Age</code>, <code>Address</code>.</p>
  
  <p>I have also window with text boxes <code>Name</code>, <code>Age</code>, <code>Address</code>.</p>
  
  <p>The <code>Data</code> object can change any time.</p>
  
  <p>How can I bind the <code>Data</code> object to the text boxes and follow after object changes?</p>
  
  <p>I know there is <code>INotifyPropertyChanged</code> and "dependency-properties" but I do not know how to use them.</p>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>public class MyData : INotifyPropertyChanged
  {
    private string _name;
  
    public string Name
    {
      get
      {
        return _name;
      }
      set
      {
        if (_name != value)
        {
          _name = value;
          OnPropertyChnged("Name");
        }
      }
     }
     public event PropertyChangedEventHandler PropertyChanged;
  
     protected void OnPropertyChanged(string name)
     {
       ProppertyChangedEventHandler handler = PropertyChanged;
       if (handler != null) handler(this, new PropertyChangedEventArgs(name));
     }
  }
  </code></pre>
  
  <p>XAML code:</p>
  
  <pre><code>xmlns:myApp="clr-namespace:MyApp"
  &lt;Window.Resources&gt;&lt;myApp:MyData x:key = data/&gt;&lt;/WindowResources&gt;
  &lt;TextBox&gt;&lt;TextBox.Text&gt;&lt;Binding Source="{StaticResource data}" Path="Name" UpdateSourceTrigger="PropertyChanged"/&gt;&lt;/TextBox.Text&gt;&lt;/TextBox&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>class OtherClass
  {
    private MyData data;
    //the window that have the binding textbox
    private MyWindow window;
    public OtherClass()
    {
      data = new MyData();
      data.Name = "new name"
      window = new MyWindow();
      window.show();
    }
  }
  </code></pre>