title: Why is my ControlTemplate bound to a "local" source, when it is setup to bind to a ParentTemplate?
body: <p>I have a piece of code that is almost identical to another -- they both follow, more or less, the same exact template...</p>
  
  <pre><code>&lt;Style TargetType="{x:Type controls:LookupControl}"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="{x:Type controls:LookupControl}"&gt;
                  &lt;controls:AutoCompleteTextBox Margin="5,2,2,2"
                                                EntityItemTemplate="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                                             Path=ItemTemplate,
                                                                             Mode=TwoWay,
                                                                             UpdateSourceTrigger=PropertyChanged}"
                                                Items="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                                Path=SearchResults}"
                                                SelectAllOnFocus="True"
                                                Text="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                               Path=Text,
                                                               Mode=TwoWay,
                                                               UpdateSourceTrigger=PropertyChanged}"
                                                Watermark="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                                    Path=Watermark,
                                                                    Mode=TwoWay}"
                                                Value="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                                Path=Value,
                                                                Mode=TwoWay,
                                                                UpdateSourceTrigger=PropertyChanged}" /&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;Style TargetType="{x:Type controls:SomeEntityControl}"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="{x:Type controls:SomeEntityControl}"&gt;
                  &lt;Grid&gt;
                      &lt;Grid.RowDefinitions&gt;
                          &lt;RowDefinition Height="Auto" /&gt;
                          &lt;RowDefinition Height="Auto" /&gt;
                      &lt;/Grid.RowDefinitions&gt;
  
                      &lt;TextBlock Grid.Row="0"
                                 Margin="2"
                                 Style="{DynamicResource InputTitle}"
                                 Text="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                Path=Label,
                                                Mode=TwoWay,
                                                UpdateSourceTrigger=PropertyChanged}" /&gt;
  
                      &lt;controls:AutoCompleteTextBox Grid.Row="1"
                                                    Margin="5,2,2,2"
                                                    DisplayMemberPath="Name"
                                                    Items="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                                    Path=SomeEntities}"
                                                    SearchMemberPath="Name"
                                                    SelectAllOnFocus="True"
                                                    Text="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                                   Path=Text,
                                                                   Mode=TwoWay,
                                                                   UpdateSourceTrigger=PropertyChanged}"
                                                    Value="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                                    Path=Value,
                                                                    Mode=TwoWay,
                                                                    UpdateSourceTrigger=PropertyChanged}"&gt;
                          &lt;controls:AutoCompleteTextBox.EntityItemTemplate&gt;
                              &lt;DataTemplate DataType="{x:Type entities:SomeEntity}"&gt;
                                  &lt;TextBlock Text="{Binding Name}" /&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/controls:AutoCompleteTextBox.EntityItemTemplate&gt;
                      &lt;/controls:AutoCompleteTextBox&gt;
                  &lt;/Grid&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>They are almost identical -- and the first is the one causing me issues.  Everything binds correctly in Snoop, but for some reason, Value (on LookupControl) is bound to "Local" rather than "ParentTemplate".  In SomeEntityControl it is bound to ParentTemplate successfully.</p>
  
  <p>The "AutoCompleteTextBox" in the LookupControl's value is Local and null.  In the SomeEntityControl, it is ParentTemplate (and at least, still null -- but it changes whenever something IS selected).</p>
  
  <p>There is <em>nothing</em> in the LookupControl that manually overrides Value and sets it as anything, which could be a potential problem.  I'm just curious if I missed something.  I don't understand how the TemplateBinding is being ignored by one and applied by another...</p>
  
  <p>To add more detail, SomeEntityControl's value is statically typed to SomeEntity -- so the Value property on that is SomeEntity.  On the other, it is of type Object.  I tried swapping from type Object to string, but no luck -- it stayed bound Locally still, for some reason.</p>
  
  <p>(Inside LookupControl)</p>
  
  <pre><code>    public static readonly DependencyProperty ValueProperty =
          DependencyProperty.Register("Value", typeof(object), typeof(LookupControl), new UIPropertyMetadata(null));
  </code></pre>
  
  <p>(Inside SomeEntityControl)</p>
  
  <pre><code>    public static readonly DependencyProperty ValueDependencyProperty =
          DependencyProperty.Register("Value", typeof(SomeEntity), typeof(SomeEntityControl), new UIPropertyMetadata(null));
  </code></pre>
  
  <p>Any thoughts?  I know for sure the Style's are being set correctly...  I know that it SHOULD be bound -- there are no errors/exceptions to show a problem occuring in the Tracer/Output window on the Value property on LookupControl...</p>
  
  <p>I'm wondering if there is potentially a weird error that if a TemplateParent isn't found that it reverts to local or something...?</p>