title: How to create my own PropertyChangedEventArgs for INotifyPropertyChanged interface?
body: <p>I have come across an issue where i get in an endless loop between my <code>DataModel</code> and <code>ViewModel</code> with <code>PropertyChanged event</code>.</p>
  
  <p>My structure:</p>
  
  <pre><code>public class SomeDataModel : DataModelBase
  {
      public SomeDataModel()
      {
  
      }
  
      public object SomeProperty
      {
          get
          {
              //
          }
          set;
          {
              //
              OnPropertyChanged("SomeProperty");
          }
      }
  
      public bool SomeMethod()
      {
          SomeProperty = SomeNewObject
      }
  }
  
  public class SomeViewModel : ViewModelBase
  {
      public SomeViewModel()
      {
  
      }
  
      public SomeDataModel SomeDataModel
      {
          get;
          set;
      }
  
      public object SomeProperty
      {
          get
          {
              return SomeDataModel.SomeProperty;
          }
          set
          {
              SomeDataModel.SomeProperty = value;
              OnPropertyChanged("SomeProperty");
          }
      }
  }
  </code></pre>
  
  <p>Both <code>ViewModel</code> and <code>DataModel</code> implements <code>INotifyPropertyChanged</code>.</p>
  
  <p>Then i have a <code>listener</code> in my <code>ViewModelBase</code> for any <code>property</code> that changes in my <code>DataModel</code>:</p>
  
  <pre><code>private void DataModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
  {
      PropertyInfo toPropertyInfo = this.GetType().GetProperty(e.PropertyName);
      PropertyInfo fromPropertyInfo = DataModel.GetType().GetProperty(e.PropertyName);
  
      if (toPropertyInfo != null &amp;&amp; fromPropertyInfo != null)
      {
          if (toPropertyInfo.CanWrite &amp;&amp; fromPropertyInfo.CanRead)
          {
              toPropertyInfo.SetValue(this, fromPropertyInfo.GetValue(DataModel, null), null);
          }
      }
  }
  </code></pre>
  
  <p>So now when the <code>property</code> gets set in the <code>DataModel</code>, the listener in <code>ViewModelBase</code> catches it and updates the relevant <code>property</code> in the <code>ViewModel</code>. But the set in the <code>ViewModel</code> sets it back to the <code>DataModel</code> with causes <code>OnPropertyChanged("SomeProperty");</code> to fire agian, ending in a endless loop.</p>
  
  <ol>
  <li>Is there a quick work around to fix it? (<strong>Note</strong>: Can't change the structure)</li>
  <li>Would i be able to create my own custom class, inheriting from <code>PropertyChangedEventArgs</code> and still have my <code>INotifyPropertyChanged</code> operations working?</li>
  </ol>
  
  <p>I was thinking:</p>
  
  <pre><code>public class CustomPropertyChangedEventArgs : PropertyChangedEventArgs
  {
      public CustomPropertyChangedEventArgs(string propertyName, SomeEnum enumName)
          : base(propertyName)
      {
          //Set enum
      }
  }
  </code></pre>
  
  <p>and then in <code>OnPropertyChanged</code> i want to use the new <code>CustomPropertyChangedEventArgs</code> and pass the <code>enum</code> in that i want to use. </p>
  
  <pre><code>public void OnPropertyChanged(string propertyName)
  {
      CustomPropertyChangedEventArgs handler = this.PropertyChanged;
  
      if (handler != null)
      {
          handler(this, new CustomPropertyChangedEventArgs(propertyName, newEnum));
      }
  }
  </code></pre>