title: Validation of input wpf datagrid
body: <p>I am trying to validate the input that is entered in the Datagrid in WPF.</p>
  
  <p>I've added a validation rule to the XAML.</p>
  
  <p>The input is an object anymore but a string or int. Though the method i use expects an object. </p>
  
  <p>How can i solve the problem and make it work with an int or string. The input can only be an int between 1 and 20.</p>
  
  <p><strong>XAML</strong>:</p>
  
  <pre><code>&lt;DataGridTextColumn Header="Niveau"&gt;                                
      &lt;DataGridTextColumn.Binding&gt;                                                                 
          &lt;Binding Path="Niveau" UpdateSourceTrigger="LostFocus"&gt;
              &lt;Binding.ValidationRules&gt;                                       
                  &lt;valRule:NiveautredeValidationRule  /&gt;                                             
              &lt;/Binding.ValidationRules&gt;
          &lt;/Binding&gt;                                          
      &lt;/DataGridTextColumn.Binding&gt;                                               
  &lt;/DataGridTextColumn&gt;
  </code></pre>
  
  <p><strong>C#</strong> </p>
  
  <pre><code>public class NiveautredeValidationRule : ValidationRule
  {
      public override System.Windows.Controls.ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
      {
          NiveaudoelenViewModel doel = (value as BindingGroup).Items[0] as NiveaudoelenViewModel;
          if (doel.Niveau &lt;= 0 || doel.Niveau &gt; 20)
          {
              return new System.Windows.Controls.ValidationResult(false, "Niveau moet tussen de 1 en 20 zijn!");
          }
          else
          {
              return System.Windows.Controls.ValidationResult.ValidResult;
          }
      }
  }
  </code></pre>