title: Hide WPF validation error when window is first loaded
body: <p>When i first load the window, the button is visible and there isn't an error in the validation (no red line round textbox). </p>
  
  <p><img src="https://i.imgur.com/pga6Hjv.png" alt="what window looks like when first loaded"></p>
  
  <p>When typing values into the textbox, the validation rules work as they should.</p>
  
  <p>I would like, if possible, to have the button hidden at the start, and for the validation rules to start when the I start typing text into the box.</p>
  
  <p>Here is the code that i have so far. The xaml:</p>
  
  <pre><code> &lt;TextBox x:Name="txtName" HorizontalAlignment="Left" Height="23" Margin="156,119,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Validation.ErrorTemplate="{StaticResource ValidationErrorTemplate}"&gt;
          &lt;TextBox.Text&gt;
              &lt;Binding Path="Name" UpdateSourceTrigger="PropertyChanged" NotifyOnSourceUpdated="True"&gt;
                  &lt;Binding.ValidationRules&gt;
                      &lt;local:ValidationTest/&gt;
                  &lt;/Binding.ValidationRules&gt;
              &lt;/Binding&gt;
          &lt;/TextBox.Text&gt;
      &lt;/TextBox&gt;
  
  
      &lt;Button x:Name="btn1" Content="Button" HorizontalAlignment="Left" Margin="85,221,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"&gt;
          &lt;Button.Style&gt;
              &lt;Style TargetType="Button"&gt;
                  &lt;Setter Property="Visibility" Value="Hidden"/&gt;
                  &lt;Style.Triggers&gt;
                      &lt;MultiDataTrigger&gt;
                          &lt;MultiDataTrigger.Conditions&gt;
                              &lt;Condition Binding="{Binding Path=(Validation.HasError), ElementName=txtName}" Value="False"/&gt;
                          &lt;/MultiDataTrigger.Conditions&gt;
                          &lt;Setter Property="Visibility" Value="Visible"&gt;&lt;/Setter&gt;
                      &lt;/MultiDataTrigger&gt;
                  &lt;/Style.Triggers&gt;
              &lt;/Style&gt;
          &lt;/Button.Style&gt;
      &lt;/Button&gt;
  </code></pre>
  
  <p>My validation logic:</p>
  
  <pre><code>class ValidationTest : ValidationRule
  {
      private int result;
      public override ValidationResult Validate(object value, CultureInfo cultureInfo)
      {
          if (value == null || string.IsNullOrEmpty(value.ToString()))
          {
              return new ValidationResult(false, "Value cannot be empty.");
          }
          if (value.ToString().Length &gt; 4)
          {
              return new ValidationResult(false, "Name cannot be more than 20 characters long.");
          }
          return ValidationResult.ValidResult;
      }
  }
  </code></pre>
  
  <p>The error template i am using:</p>
  
  <pre><code>    &lt;Window.Resources&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;ControlTemplate x:Key="ValidationErrorTemplate"&gt;
          &lt;DockPanel&gt;
              &lt;Border BorderBrush="Red" BorderThickness="1.5"&gt;
                  &lt;AdornedElementPlaceholder x:Name="ErrorAdorner"&gt;&lt;/AdornedElementPlaceholder&gt;
              &lt;/Border&gt;
          &lt;/DockPanel&gt;
      &lt;/ControlTemplate&gt;
  &lt;/Window.Resources&gt;
  </code></pre>
  
  <p>I have tried to update the binding when the window loads by using <code>txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource();</code>, but that shows the validation error (red line around textbox). However, the button is hidden, so is there any way of hiding the validation error until the user types text into the textbox?</p>
  
  <p><img src="https://i.imgur.com/H3Hnuwp.png" alt="what i get when i update the binding when the windows loads"></p>
  
  <p>Am i approaching this in the right way?</p>