title: WPF Model validation in MVVM pattern
body: <p>I've read so far about WPF validation rules and the different approach (using <code>IDataErrorInfo</code> , <code>INotifyDataErrorInfo</code>, <code>DataAttributes</code> and so on), but none matches my needs. I would like to have a model validator which validates the entire view model (I need to set an error if a property has a positive value and another field is set to 1)</p>
  
  <p>What is the best approach for handling this scenario?</p>
  
  <p>Thanks</p>
  
  <p>Update #1: I forget to say I'm under Framework 4.0 and no possibility to upgrade to 4.5</p>
  
  <p>Update #2: I've created a smaller project</p>
  
  <p>Here's my View :</p>
  
  <pre><code>&lt;UserControl x:Class="TaskException.Views.SampleView"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
           xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
           mc:Ignorable="d" 
           &gt;
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="30"&gt;&lt;/RowDefinition&gt;
          &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
      &lt;/Grid.RowDefinitions&gt;
  
      &lt;ComboBox Grid.Row="0" ItemsSource="{Binding DropdownList}" DisplayMemberPath="Description" SelectedValuePath="Id" SelectedValue="{Binding Obj.Sign}"&gt;
  
      &lt;/ComboBox&gt;
      &lt;telerik:RadMaskedNumericInput Grid.Row="1" Value="{Binding Obj.Qty, ValidatesOnDataErrors=True}"&gt;&lt;/telerik:RadMaskedNumericInput&gt;
  
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>My ViewModel :</p>
  
  <pre><code>public class SampleViewModel : Screen
  {
  
      private List&lt;DropDownOggetto&gt; dropdownList;
  
      private DropDownOggetto selectedDropDownList;
  
      private Dummy obj;
  
      public DropDownOggetto SelectedDropDownList
      {
          get
          {
              return this.selectedDropDownList;
          }
          set
          {
              this.selectedDropDownList = value;
              NotifyOfPropertyChange(()=&gt;SelectedDropDownList);
          }
      }
  
      public List&lt;DropDownOggetto&gt; DropdownList
      {
          get
          {
              return this.dropdownList;
          }
          set
          {
              this.dropdownList = value;
              NotifyOfPropertyChange(()=&gt;DropdownList);
          }
      }
  
      public Dummy Obj
      {
          get
          {
              return this.obj;
          }
          set
          {
              this.obj = value;
              NotifyOfPropertyChange(() =&gt; Obj);
          }
      }
  
      public SampleViewModel()
      {
          Obj = new Dummy
          {
              Qty = 2000,
              Sign = 0
          };
  
          var lst = new List&lt;DropDownOggetto&gt;();
  
          lst.Add(new DropDownOggetto { Id = 0, Description = "Buy" });
          lst.Add(new DropDownOggetto { Id = 1, Description = "Sell" });
  
          DropdownList = lst;
      }
  
  }
  </code></pre>
  
  <p>And the models</p>
  
  <pre><code>public class DropDownOggetto
  {
      public int Id { get; set; }
      public string Description { get; set; }
  }
  
  public class Dummy : IDataErrorInfo 
  {
      public int Sign { get; set; }
  
      public double Qty { get; set; }
  
      public string Error
      {
          get { return "Some kind of error";}
      }
  
      public string this[string columnName]
      {
          get
          {
              if (columnName == "Qty")
              {
                  if (Sign == 0 &amp;&amp; Qty &lt; 0)
                      return "Qty must be positive";
                  else if(Sign ==1 &amp;&amp; Qty &gt;=0)
                  {
                      return "Qty must be negative";
                  }
              }
  
  
              return null;
          }
      }
  }
  </code></pre>
  
  <p>This simplier sample works almost fine except for the fact that If I've a positive quantity in the RadMaskedNumericInput and I change the dropdown  the validation on the property below is not called... how can I signal it? have I to convert the Sign Qty auto-properties to properties and notify them?</p>
  
  <p>Thanks</p>