title: Why is my WPF Validation Error not getting displayed?
body: <p>I have defined a control template for showing Validation Errors:<br></p>
  
  <pre><code>&lt;ControlTemplate x:Key="validationTemplate"&gt;
                      &lt;DockPanel LastChildFill="True"&gt;
                          &lt;TextBlock DockPanel.Dock="Right"  
                                     Background="Red"
                                     TextWrapping="Wrap"&gt;
                              &lt;TextBlock.Text&gt;
                                  &lt;Binding Path="(Validation.Errors)[0].ErrorContent"
          RelativeSource="{x:Static RelativeSource.Self}"&gt;                                        
                                  &lt;/Binding&gt;
                              &lt;/TextBlock.Text&gt;                                
                          &lt;/TextBlock&gt;
                          &lt;AdornedElementPlaceholder &gt;&lt;/AdornedElementPlaceholder&gt;
                      &lt;/DockPanel&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>I have defined a TextBox as follows:</p>
  
  <pre><code>&lt;TextBox Text="{Binding Text}" PreviewTextInput="textBox1_PreviewTextInput"  
        Validation.ErrorTemplate="{StaticResource validationTemplate}" /&gt;
  </code></pre>
  
  <p>I am setting the validation from code behind as follows:</p>
  
  <pre><code>    private void textBox1_PreviewTextInput(object sender, TextCompositionEventArgs e)
      {
          TextBox txtBox = (TextBox)sender;
       ....
       ....
  
       ValidationError validationError = new ValidationError(new DummyValidator(),
              txtBox.GetBindingExpression(TextBox.TextProperty));
          Validation.MarkInvalid(txtBox.GetBindingExpression(TextBox.TextProperty), validationError);            
          validationError.ErrorContent = "This is wrong input";
          e.Handled = true;
      }
  </code></pre>
  
  <p><br></p>
  
  <p><strong>Now the problem is The Validation is getting fired and a red strip is shown but the error message inside that is not getting displayed!!
  May be I am wrong with this <br></strong> It is throwing some exception in console (index out of bounds exception)</p>
  
  <pre><code>&lt;Binding Path="(Validation.Errors)[0].ErrorContent"
          RelativeSource="{x:Static RelativeSource.Self}"&gt;  
  </code></pre>
  
  <p>Please guide me regarding Where am I going wrong?</p>