title: NotifyPropertyChanged through code
body: <p>I have a class that contains two other objects.</p>
  
  <p>A variable in the first object bind to <code>WPF</code> element, call it <code>X</code>.</p>
  
  <p>A similar variable in the other object.</p>
  
  <p>I want that when the PropertyChanged event happens, it will change the variable in the second object.</p>
  
  <p>Here is the code that does not work for me:</p>
  
  <p>The class that contains the variables: (I had register to property changed event)</p>
  
  <pre><code>private Class1 _var1;
      public Class1 Var1
      {
          get { return _var1; }
          set
          {
              _var1= value;
              if (_var1!= null)
                  _var1.PropertyChanged += new PropertyChangedEventHandler(_var1_PropertyChanged);
              else
                  _var1.PropertyChanged -= new PropertyChangedEventHandler(_var1_PropertyChanged);
          }
      }
  
      void _var1_PropertyChanged(object sender, PropertyChangedEventArgs e)
      {
        if(e.PropertyName=="X")
          Var2.X= Var1.X;
      }
  
      private Class2 _var2;
      public Class2 Var2
      {
          get { return _var2; }
          set { _var2= value; }
      }
  </code></pre>
  
  <p>Class 1:</p>
  
  <pre><code>    private int _x;
      public int X
      {
          get { return _x; }
          set
          {
              if (_x!= value)
              {
                  _x= value;
                  NotifyPropertyChanged("X");
              }
          }
      }
  </code></pre>
  
  <p>class 2:</p>
  
  <pre><code>public int X { get; set; }
  </code></pre>
  
  <p><code>PropertyChanged</code> work in class 1 but he did not come to an event I created in a class that contains the two variables, why?</p>