title: Provide value on 'System.Windows.Data.Binding' threw an exception
body: <p>I am adding a validation rule to a textbox (following examples on <a href="http://adamnathan.net/" rel="noreferrer">WPF 4 Unleashed </a> by Adam Nathan)</p>
  
  <p>When starting an application, I am faced with the following cryptic error message</p>
  
  <blockquote>
    <p>Provide value on 'System.Windows.Data.Binding' threw an exception</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/6UbmL.png" alt="alt text"></p>
  
  <p><strong>What does the error mean and what needs to be done to address the problem?</strong></p>
  
  <p>Here is the full source code </p>
  
  <p><strong>XAML</strong>
  </p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;Style x:Key="controlStyle" TargetType="{x:Type Control}"&gt;
          &lt;Style.Triggers&gt;
              &lt;Trigger Property="IsMouseOver" Value="True"&gt;
                  &lt;Setter Property="RenderTransform"&gt;
                      &lt;Setter.Value&gt;
                          &lt;RotateTransform Angle="20" /&gt;
                      &lt;/Setter.Value&gt;
                  &lt;/Setter&gt;
                  &lt;Setter Property="Foreground" Value="Black" /&gt;
              &lt;/Trigger&gt;
          &lt;/Style.Triggers&gt;
          &lt;Setter Property="FontSize" Value="22" /&gt;
          &lt;Setter Property="Background" Value="Purple" /&gt;
          &lt;Setter Property="Foreground" Value="White" /&gt;
          &lt;Setter Property="Height" Value="50" /&gt;
          &lt;Setter Property="Width" Value="50" /&gt;
          &lt;Setter Property="RenderTransformOrigin" Value=".5,.5" /&gt;
          &lt;Setter Property="RenderTransform"&gt;
              &lt;Setter.Value&gt;
                  &lt;RotateTransform Angle="10" /&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
          &lt;Setter Property="TextBox.TextAlignment" Value="Right" /&gt;
      &lt;/Style&gt;
      &lt;Style x:Key="textBoxStyle" TargetType="{x:Type TextBox}"&gt;
          &lt;Style.Triggers&gt;
              &lt;Trigger Property="Validation.HasError" Value="True"&gt;
                  &lt;Setter Property="Background" Value="Red" /&gt;
                  &lt;Setter Property="ToolTip" 
                          Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" /&gt;
              &lt;/Trigger&gt;
          &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
  &lt;/Window.Resources&gt;
  
  &lt;StackPanel Orientation="Vertical"&gt;
      &lt;StackPanel Orientation="Horizontal"&gt;
          &lt;TextBox Style="{StaticResource textBoxStyle}"&gt;
              &lt;TextBox.Text&gt;
                  &lt;Binding&gt;
                      &lt;Binding.ValidationRules&gt;
                          &lt;local:JpgValidationRule /&gt;
                      &lt;/Binding.ValidationRules&gt;
                  &lt;/Binding&gt;
              &lt;/TextBox.Text&gt;
          &lt;/TextBox&gt;
      &lt;/StackPanel&gt;
  
      &lt;StackPanel Orientation="Horizontal"&gt;
          &lt;Button Style="{StaticResource controlStyle}"&gt;1&lt;/Button&gt;
          &lt;ComboBox Style="{StaticResource controlStyle}"&gt;
              &lt;ComboBox.Items&gt;2&lt;/ComboBox.Items&gt;
          &lt;/ComboBox&gt;
          &lt;Expander Style="{StaticResource controlStyle}" Content="3" /&gt;
          &lt;TabControl Style="{StaticResource controlStyle}"&gt;
              &lt;TabControl.Items&gt;4&lt;/TabControl.Items&gt;
          &lt;/TabControl&gt;
          &lt;ToolBar Style="{StaticResource controlStyle}"&gt;
              &lt;ToolBar.Items&gt;5&lt;/ToolBar.Items&gt;
          &lt;/ToolBar&gt;
          &lt;!--&lt;InkCanvas Style="{StaticResource controlStyle}" /&gt;--&gt;
          &lt;TextBox Style="{StaticResource controlStyle}" Text="7" /&gt;
      &lt;/StackPanel&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>JpgValidationRule</strong></p>
  
  <pre><code>using System.Globalization;
  using System.IO;
  using System.Windows.Controls;
  
  namespace StylesDemo
  {
      public class JpgValidationRule : ValidationRule
      {
          public override ValidationResult Validate(object value, CultureInfo cultureInfo)
          {
              string fileName = value.ToString();
  
              // Reject nonexistent files:
              if (!File.Exists(fileName))
                  return new ValidationResult(false, "Value is not a valid file!");
  
              // Reject files that don't end in .jpg:
              if (Path.GetExtension(fileName).ToUpper() != ".JPG")
                  return new ValidationResult(false, "Value is not a .jpg file!");
  
              return new ValidationResult(true, null);
          }
      }
  }
  </code></pre>