title: How to perform validation in richtextbox using IDataerroInfo Interface?
body: <p>I'm trying to implement Idataerrorinfo interface on a richtextbox for custom validation. I sucessfully implemented it for a textbox when i followed the same pattern to implement for richtextbox nothing happens around the richtextbox.</p>
  
  <p>windows.xaml:</p>
  
  <pre><code> &lt;Window.Resources&gt;
          &lt;ControlTemplate x:Key="ErrorTemplate"&gt;
              &lt;DockPanel LastChildFill="True"&gt;
                  &lt;Border BorderBrush="Red" BorderThickness="1"&gt;
                      &lt;AdornedElementPlaceholder /&gt;
                  &lt;/Border&gt;
              &lt;/DockPanel&gt;
          &lt;/ControlTemplate&gt;
    &lt;Style TargetType="TextBox"&gt;
  
              &lt;Style.Triggers&gt;
  
                  &lt;Trigger Property="Validation.HasError" Value="true"&gt;
  
                      &lt;Setter Property="ToolTip"
  
            Value="{Binding RelativeSource={x:Static RelativeSource.Self},
  
  Path=(Validation.Errors)[0].ErrorContent}"/&gt;
  
                  &lt;/Trigger&gt;
  
              &lt;/Style.Triggers&gt;
  
          &lt;/Style&gt;
  
     &lt;Style TargetType="RichTextBox"&gt;
  
              &lt;Style.Triggers&gt;
  
                  &lt;Trigger Property="Validation.HasError" Value="true"&gt;
  
                      &lt;Setter Property="ToolTip"
  
            Value="{Binding RelativeSource={x:Static RelativeSource.Self},
  
  Path=(Validation.Errors)[0].ErrorContent}"/&gt;
  
                  &lt;/Trigger&gt;
  
              &lt;/Style.Triggers&gt;
  
          &lt;/Style&gt;
  
      &lt;/Window.Resources&gt;
  
  
                          &lt;TextBlock Grid.Column="0" Text="Comments" HorizontalAlignment="Center"  VerticalAlignment="Center" Width="70" /&gt;
  
  
  
  &lt;RichTextBox Grid.Column="1"&gt;
           &lt;FlowDocument PageHeight="180"&gt;
                 &lt;Paragraph&gt;
                     &lt;Run Text="{Binding informationdata.Usercomments, Mode=TwoWay, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"  Validation.ErrorTemplate="{StaticResource ErrorTemplate}"/&gt;
                       &lt;/Paragraph&gt;
                       &lt;/FlowDocument&gt;
                        &lt;/RichTextBox&gt;
  
   &lt;TextBlock Grid.Column="5" Text="Time Taken" HorizontalAlignment="Center"  VerticalAlignment="Center" Width="79" /&gt;
  
  
   &lt;TextBox Grid.Column="6" IsEnabled="{Binding informationdata.Isdisabled}" HorizontalAlignment="Center" VerticalAlignment="Center"  Width="99" Height="19" Text="{Binding informationdata.Timetaken, Mode=TwoWay, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"   Validation.ErrorTemplate="{StaticResource ErrorTemplate}"/&gt;
  </code></pre>
  
  <p>Viewmodel.cs:</p>
  
  <pre><code>   private string GetValidationError(string propertyName)
      {
          string errorMsg = null;
  
          switch (propertyName)
          {
  
              case "Timetaken":
                  if ((propertyName.Equals("Timetaken")))
                  {
                      if (String.IsNullOrEmpty(this.Timetaken))
  
                          errorMsg = "Please provide the TimeTaken";
                      else if (CheckInteger(Timetaken) == false)
                          errorMsg = "The given TimeTaken is not a Number";
                      else if (Timetaken.Length &gt; 480)
                          errorMsg = "The TimeTaken in mins should be less than 480 Mins";
  
                  }
  
                  break;
  
              case "Usercomments":
                  if ((propertyName.Equals("Usercomments")))
                  {
                      if (String.IsNullOrEmpty(this.Usercomments))
  
                          errorMsg = "Please provide the User comments";
  
  
                  }
  
                  break;
  
          }
          return errorMsg;
      }
  
      public string this[string columnName]
  
      {
  
          get
  
          {
              return GetValidationError(columnName);
  
          }
  
      }
  </code></pre>
  
  <p>In the above code the textbox validation works fine but with richtextbox nothing happens around it and i'm not sure on how to find what is wrong with it.</p>