title: TextBox with Error Template with code
body: <p>I'm trying to add some textbox to a form by code, not XAML. And using Error Validation. I have the following code:</p>
  
  <pre><code>SearchTextBox stb = new SearchTextBox()
  {
      Name = "stbRelatorio_" + id
  };
  
  // Create a new Binding.
  Binding bindingStb = new Binding();
  bindingStb.Source = model;
  bindingStb.Path = new PropertyPath("ReportFile[" + id + "]");
  stb.SetBinding(SearchTextBox.FileNameProprety, bindingStb);
  
  BindingExpression bindingExpression =
      BindingOperations.GetBindingExpression(stb, SearchTextBox.FileNameProprety);
  
  BindingExpressionBase bindingExpressionBase =
      BindingOperations.GetBindingExpressionBase(stb, SearchTextBox.FileNameProprety);
  
  ValidationError validationError =
      new ValidationError(new ExceptionValidationRule(), bindingExpression);
  
  Validation.MarkInvalid(bindingExpressionBase, validationError);
  
  ControlTemplate ct = this.Resources["validationErrorTemplate"] as ControlTemplate;
  </code></pre>
  
  <p>When I do this, I get the default behavior when there's no text inserted (that's my error case). The red box around the text box. What I want now is to use a custom Adorner Layout and I build it on XAML</p>
  
  <pre><code>&lt;ControlTemplate x:Name="validationErrorTemplate" x:Key="validationErrorTemplate"&gt;
      &lt;DockPanel&gt;
          &lt;StackPanel Orientation="Horizontal" DockPanel.Dock="Top"&gt;
              &lt;Grid Width="12" Height="12"&gt;
                  &lt;Ellipse Width="12" Height="12" 
                      Fill="Red" HorizontalAlignment="Center" 
                      VerticalAlignment="Center"&gt;&lt;/Ellipse&gt;
                  &lt;TextBlock Foreground="White" FontWeight="Heavy" 
                      FontSize="8" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center"
                      ToolTip="{Binding ElementName=ErrorAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"&gt;
                      X
                  &lt;/TextBlock&gt;
              &lt;/Grid&gt;
              &lt;TextBlock Foreground="Red" FontWeight="12" Margin="2,0,0,2" 
                     Text="{Binding ElementName=ErrorAdorner, 
                     Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"&gt;
              &lt;/TextBlock&gt;
          &lt;/StackPanel&gt;
          &lt;AdornedElementPlaceholder x:Name="ErrorAdorner" /&gt;
      &lt;/DockPanel&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>But when I try to set the ErrorTemplate:</p>
  
  <pre><code>Validation.SetErrorTemplate(stb, ct);
  </code></pre>
  
  <p>I don't get any error validation, not even the default template.</p>
  
  <p>Am I missing something?</p>