title: How to validate user input in a textbox with updateSourceTrigger="Explicit" with xaml:C#?
body: <p>I'm new in WPF/XAML and I need help.
  I didn't found a response to my question in the existing questions/answers or I failed in using them.
  I have a wpf application with several textboxes, checkboxes and comboboxes : all are binded to properties of my Object.
  I have also a cancel and a validate buttons. To not update the properties bind to my textboxes (and etc...), I used UpdateSourceTrigger =&quot;Explicit&quot;.
  I would like to use a ValidationRule when Focus is lost on my email address text box but I don't know how to do.</p>
  <p>My XAML is :</p>
  <pre><code>&lt;TextBox Margin=&quot;5 0 5 0&quot; x:Name=&quot;txtBox_mailSender&quot;  
                                       Validation.ErrorTemplate=&quot;{StaticResource ValidationTemplate}&quot;&gt;
                              &lt;TextBox.Text&gt;
                                  &lt;Binding Path=&quot;SenderMailAddress&quot;
                                           UpdateSourceTrigger=&quot;Explicit&quot;&gt;
                                      &lt;Binding.ValidationRules&gt;
                                          &lt;local:EmailAddressValidator /&gt;
                                      &lt;/Binding.ValidationRules&gt;
                                  &lt;/Binding&gt;
                              &lt;/TextBox.Text&gt;
                          &lt;/TextBox&gt;
  </code></pre>
  <p>My EmailAddressValidator :</p>
  <pre><code>public class EmailAddressValidator : ValidationRule
  {
      //public override ValidationResult Validate(object value, CultureInfo cultureInfo)
      //{
      //  Regex mailAddressRegex = new Regex(@&quot;^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}&quot; +
      //        @&quot;\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\&quot; +
      //        @&quot;.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$&quot;);
  
      //  if(!mailAddressRegex.IsMatch((string)value))
      //  {
      //      return new ValidationResult(false, $&quot;Adresse E-mail invalide.&quot;);
      //  }
      //  return new ValidationResult(true, null);
      //}
  
      public override ValidationResult Validate(object value, CultureInfo cultureInfo)
      {
          try
          {
              new MailAddress(value.ToString());
  
          }
          catch (Exception)
          {
              return new ValidationResult(false, &quot;Adresse E-mail invalide.&quot;);
          }
  
          return new ValidationResult(true, null);
      }
  }
  </code></pre>
  <p>My Control Template (Validation Template) but I think it's not necessary since the red border is good for me :</p>
  <pre><code>&lt;ControlTemplate x:Key=&quot;ValidationTemplate&quot;&gt;
      &lt;DockPanel&gt;
          &lt;TextBlock Foreground=&quot;Red&quot; &gt;!&lt;/TextBlock&gt;
          &lt;AdornedElementPlaceholder/&gt;
      &lt;/DockPanel&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  <p>I tried with the LostFocus event but I don't know how to transform the textbox into a &quot;textbox with errors&quot;.</p>
  <p>An extract of my object with the e-mail property :</p>
  <pre><code>public class MyObject
  {
      public String SenderMailAddress
              {
                  set
                  {
                      if (SenderMailAddress != value)
                      {
                          _senderMailAddress = value;
                          OnSpecificModification();
                      }
                  }
                  get
                  {
                      return _senderMailAddress;
                  }
              }
              private String _senderMailAddress = &quot;&quot;;
   }
  </code></pre>
  <p>Thank you for your help.</p>