title: Show error message text box in WPF
body: <p>When my textbox is empty/null, i need to display "Required".</p>
  
  <p>In my xaml:</p>
  
  <pre><code>  &lt;TextBox Name="txtLastName"  Grid.Column="1"  Grid.Row="1"  Margin="3"&gt;
              &lt;TextBox.Text&gt;
                  &lt;Binding Path="LastName"&gt;
                      &lt;Binding.ValidationRules&gt;
                          &lt;validators:Contractor
                                      MinimumLength="1" 
                                      MaximumLength="40"
                                      ErrorMessage="Required" /&gt;
                      &lt;/Binding.ValidationRules&gt;
                  &lt;/Binding&gt;
              &lt;/TextBox.Text&gt;
          &lt;/TextBox&gt;
  </code></pre>
  
  <p>In my class:</p>
  
  <pre><code>public string LastName
          {
              get { return _lastName; }
              set
              {
                  _lastName = value;
                NotifyPropertyChanged("LastName");               
  
              }
          }   
  
  public event PropertyChangedEventHandler PropertyChanged;
  
      private int _minimumLength = -1;
      private int _maximumLength = -1;
      private string _errorMessage;
  
      public int MinimumLength
      {
          get { return _minimumLength; }
          set { _minimumLength = value; }
      }
  
      public int MaximumLength
      {
          get { return _maximumLength; }
          set { _maximumLength = value; }
      }
  
      public string ErrorMessage
      {
          get { return _errorMessage; }
          set { _errorMessage = value; }
      }
  
      public override ValidationResult Validate(object value,CultureInfo cultureInfo)
      {
          ValidationResult result = new ValidationResult(true, null);
          string inputString = (value ?? string.Empty).ToString();
          if (inputString.Length &lt; this.MinimumLength || value==null ||
                 (this.MaximumLength &gt; 0 &amp;&amp;
                  inputString.Length &gt; this.MaximumLength))
          {
              result = new ValidationResult(false, this.ErrorMessage);
          }
          return result;
      }
  
  
    private void NotifyPropertyChanged(string propertyName)
          {
              if (PropertyChanged != null)
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
  </code></pre>
  
  <p>What i get is the textbox turns into red border when the data is null/empty and i am not able to see the "Required" error message, any thoughts?</p>