title: How to add validation to view model properties or how to implement INotifyDataErrorInfo
body: <p>I have a data collection of type ObservableCollection (say instance as myClassTypes). After some user operation, this myClassTypes populated with values in ViewModel. In view, there is a TextBox where user can enter text. I need to validate textbox data against myClassTypes values. So if myClassTypes contains the text inserted by User in textbox, Validation is passed otherwise it will fail.
  My code snippet is:
  ViewModel:</p>
  
  <pre><code>public ObservableCollection &lt; MyClassType &gt; ViewModelClassTypes {
      get {
  
          return _myClassTypes;
      }
      set {
          _myClassTypes = value;
          NotifyOfPropertyChange(() = &gt;MyClassTypes);
      }
  }
  
  public class TestValidationRule: ValidationRule {
      public ObservableCollection &lt; MyClassType &gt; MyClassTypes {
          get = &gt;(ObservableCollection &lt; MyClassType &gt; ) GetValue(MyClassTypesProperty);
          set = &gt;SetValue(MyClassTypesProperty, value);
      }
  }
  </code></pre>
  
  <p>FYI : MyClassTypesProperty is a dependency property</p>
  
  <p>My View.xaml is : </p>
  
  <pre><code>&lt;TextBox&gt;
      &lt;TextBox.Text&gt;
          &lt;Binding UpdateSourceTrigger="PropertyChanged"&gt;
              &lt;Binding.ValidationRules&gt;
                  &lt;validationRules:TestValidationRule MyClassTypes="{Binding ViewModelClassTypes}"/&gt;
              &lt;/Binding.ValidationRules&gt;
          &lt;/Binding&gt;
      &lt;/TextBox.Text&gt;
  &lt;/TextBox&gt;
  </code></pre>
  
  <p>I am not able to get ViewModelClassTypes populated value in MyClassTypes.  Can anyone please suggest what's wrong I am doing ?</p>