title: TemplateBinding Not working on ValidationRules Dependency Property
body: <p>I am trying to make cutom validator controls but dont know why the Message Property that i have on the ValidationRules that i wanted to bind to the templated parent. It works runs but everytime its empty. Dont know why its empty everytime.</p>
  
  <p>The Sample project can be found <a href="https://skydrive.live.com/redir.aspx?cid=d8443a8832e1fdf8&amp;resid=D8443A8832E1FDF8!295&amp;parid=D8443A8832E1FDF8!137&amp;authkey=!AOUj5HAyEzeR1gs" rel="nofollow">here</a></p>
  
  <p><strong>STYLE</strong></p>
  
  <pre><code>   &lt;Style TargetType="{x:Type local:RequiredFieldBox}"&gt;
      &lt;Setter Property="Template"&gt;
        &lt;Setter.Value&gt;
           &lt;ControlTemplate TargetType="{x:Type local:RequiredFieldBox}"&gt;
                  &lt;StackPanel Orientation="Vertical"&gt;
  
                      &lt;TextBox&gt;
                          &lt;Binding  RelativeSource="{RelativeSource TemplatedParent}" Path="Text"&gt;
                          &lt;Binding.ValidationRules&gt;
                              &lt;rule:RequiredFieldRule&gt;
                                  &lt;rule:RequiredFieldRule.Params&gt;
                                      &lt;rule:ValidationParams 
                                          Message="{TemplateBinding Msg}"
                                          ValidationType="{TemplateBinding Type}"/&gt;
                                  &lt;/rule:RequiredFieldRule.Params&gt;
                              &lt;/rule:RequiredFieldRule&gt; 
                          &lt;/Binding.ValidationRules&gt;
                      &lt;/Binding&gt;
                          &lt;TextBox.Style&gt;
                      &lt;Style TargetType="{x:Type TextBox}"&gt;
                        &lt;Style.Triggers&gt;
                             &lt;Trigger Property="Validation.HasError" Value="true" &gt;
                             &lt;Setter Property="Foreground" Value="Red"/&gt;
                             &lt;Setter Property="Background" Value="MistyRose"/&gt;
                             &lt;Setter Property="BorderBrush" Value="Red"/&gt;
                             &lt;Setter Property="BorderThickness" Value="1.0"/&gt;
                              &lt;Setter Property="VerticalContentAlignment" Value="Center"/&gt;
                             &lt;/Trigger&gt;
                         &lt;/Style.Triggers&gt;
                        &lt;Setter Property="Validation.ErrorTemplate"&gt;
                           &lt;Setter.Value&gt;
                              &lt;ControlTemplate&gt;
                                 &lt;StackPanel&gt;
                                    &lt;StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="40"&gt;
                                      &lt;AdornedElementPlaceholder x:Name="Holder"/&gt;
                                      &lt;Image Height="{Binding Height, ElementName=Holder}" Width="20" Margin="10,0"
                                          Source="/Images/restricted.png" ToolTip="{Binding ElementName=Holder, 
                                          Path=AdornedElement.(Validation.Errors)
                       [0].ErrorContent}"/&gt;
                                   &lt;/StackPanel&gt;
                                 &lt;/StackPanel&gt;
                              &lt;/ControlTemplate&gt;
                           &lt;/Setter.Value&gt;
                      &lt;/Setter&gt;
                   &lt;/Style&gt;
               &lt;/TextBox.Style&gt;
            &lt;/TextBox&gt;
           &lt;/StackPanel&gt;
          &lt;/ControlTemplate&gt;
     &lt;/Setter.Value&gt;
  &lt;/Setter&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>VALIDATION PARAMS CLASS</strong></p>
  
  <pre><code>public class ValidationParams : DependencyObject
  {
  
      public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(
        "Message",
        typeof(string),
        typeof(ValidationParams),
        new FrameworkPropertyMetadata(null));
      // Dependency Properties
  
      public static readonly DependencyProperty ValidationTypeProperty = DependencyProperty.Register("ValidationType",
                                                                                            typeof(RequiredFieldRule.EnmValidationType),
                                                                                            typeof(ValidationParams),
                                                                                            new FrameworkPropertyMetadata(RequiredFieldRule.EnmValidationType.FieldNotEmpty));
      public static readonly DependencyProperty FieldNameProperty = DependencyProperty.Register("FieldName",
                                                                                           typeof(string),
                                                                                           typeof(ValidationParams),
                                                                                           new FrameworkPropertyMetadata(string.Empty));
      public string FieldName
      {
          get { return (string)GetValue(FieldNameProperty); }
          set { SetValue(FieldNameProperty, value); }
      }
      // Properties
      public string Message
      {
          get { return (string)GetValue(MessageProperty); }
          set { SetValue(MessageProperty, value); }
      }
  
      [Category("ValidationType")]
      public RequiredFieldRule.EnmValidationType ValidationType
      {
          get { return (RequiredFieldRule.EnmValidationType)GetValue(ValidationTypeProperty); }
          set { SetValue(ValidationTypeProperty, value); }
  
      }
  }
  </code></pre>
  
  <p><strong>CustomControl Class</strong></p>
  
  <pre><code>public class RequiredFieldBox : Control
  {
  
      static RequiredFieldBox()
      {
          DefaultStyleKeyProperty.OverrideMetadata(typeof(RequiredFieldBox), new FrameworkPropertyMetadata(typeof(RequiredFieldBox)));
      }
      public static readonly DependencyProperty MsgProperty = DependencyProperty.Register(
       "Msg",
       typeof(string),
       typeof(RequiredFieldBox),
       new FrameworkPropertyMetadata(null)
     );
      public enum EnmValidationType
      {
          FieldNotEmpty,
          FieldNumeric,
          FieldIPAddress
      }
      public static readonly DependencyProperty TypeProperty = DependencyProperty.Register("Type",
                                                                                           typeof(RequiredFieldBox.EnmValidationType),
                                                                                           typeof(RequiredFieldBox),
                                                                                           new FrameworkPropertyMetadata(RequiredFieldBox.EnmValidationType.FieldNotEmpty));
      public EnmValidationType Type
      {
          get { return (EnmValidationType) GetValue(TypeProperty); }
          set { SetValue(TypeProperty, value);}
      }
      private static void MessageChanaged(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
          RequiredFieldBox sh = (RequiredFieldBox)d;
          if (sh.Msg != (string)e.OldValue)
              sh.Msg = (string)e.NewValue;
      }
      public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
      "Text",                               //Property name
      typeof( object ),                           //Property type
      typeof( RequiredFieldBox ));
  
      public string Msg
      {
          get { return (string)GetValue(MsgProperty); }
          set { SetValue(MsgProperty, value); }
      }
  
      public object Text
      {
          get { return GetValue(TextProperty);}
          set { SetValue(TextProperty, value); }
      }
  }
  </code></pre>
  
  <p><strong>Validation Rule Class</strong></p>
  
  <p>public class RequiredFieldRule : ValidationRule
      {</p>
  
  <pre><code>    public enum EnmValidationType
      {
          FieldNotEmpty,
          FieldNumeric,
          FieldIPAddress
      }
  
      // Local variables and objects
      private ValidationParams mParams = new ValidationParams();
  
      public ValidationParams Params
      {
          get { return mParams; }
          set { mParams = value;}
      }
  
      // Override
      public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
      {
          ValidationResult objResult = null;
          string sValue = value as string;
          objResult = new ValidationResult(true, null);
          switch (Params.ValidationType)
          {
              case EnmValidationType.FieldNotEmpty:
                  if (string.IsNullOrEmpty(sValue) == true)
                      return new ValidationResult(false, Params.Message);
                  break;
              case EnmValidationType.FieldNumeric:
                  int iValue = 0;
                  if (int.TryParse(sValue, out iValue) == false)
                      objResult = new ValidationResult(false, Params.Message);
                  break;
              case EnmValidationType.FieldIPAddress:
                  break;
          }
          return objResult;
      }
  
  }
  </code></pre>