title: Silverlight, path through TemplateBindings of UserControls
body: <p>I have a MainPage.xaml with a TextBox (Binding TextBoxText) and some nested UserControls, which all have a TextBox with a TemplateBinding / Binding too (4 TextBoxes).<br>
  I would like have the same text in every box, when I change the text somewhere.</p>
  
  <p>The solution: <a href="http://dl.dropbox.com/u/76509861/SilverlightCustomControl%20Vers.9.zip" rel="nofollow">Link</a></p>
  
  <p>What could I do to synchronize all texts?</p>
  
  <p>Thanks!</p>
  
  <p>MainPage.xaml (TextBoxText is the one, which I like to display everywhere)</p>
  
  <pre><code>&lt;myContDll:DefaultContainerTemplate Caption="NewCaption"&gt;
      &lt;StackPanel x:Name="myStackPanel"&gt;
          &lt;sdk:Label Content="Binding TextBoxText of MainPage"/&gt;
          &lt;TextBox Text="{Binding TextBoxText}"/&gt;
          &lt;myDll:MyButtonControl x:Name="ButtonControl" Count="44"
                             Button3Caption="NewButton3" 
                             Button3Visibility="Visible"  
                             DisplayText="Form2Text2"
                             TextBoxText="{Binding TextBoxText}"/&gt;
      &lt;/StackPanel&gt;
  &lt;/myContDll:DefaultContainerTemplate&gt;
  </code></pre>
  
  <p>Generic.xaml:</p>
  
  <pre><code>&lt;Style TargetType="local:MyButtonControl"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="local:MyButtonControl"&gt;
                  &lt;StackPanel&gt;
                      &lt;sdk:Label Content="inner control test"/&gt;
                      &lt;sdk:Label Content="TemplateBinding TextBoxText of MyButtonControl"/&gt;
                      &lt;TextBox Text="{TemplateBinding TextBoxText}"/&gt;
                      &lt;Button Content="{TemplateBinding Button3Caption}" Visibility="{TemplateBinding Button3Visibility}" x:Name="Button3"/&gt;
                      &lt;local:CountDisplayControl x:Name="Control1" TextBoxText="{TemplateBinding TextBoxText}" Visibility="{TemplateBinding VisibilityText1}" Count="{TemplateBinding Count}" DisplayText="{TemplateBinding DisplayText1}"/&gt;
                      &lt;local:CountDisplayControl2 x:Name="Control2" TextBoxText="{TemplateBinding TextBoxText}" Visibility="{TemplateBinding VisibilityText2}" Count="{TemplateBinding Count}" DisplayText="{TemplateBinding DisplayText2}"/&gt;
                      &lt;local:CountDisplayUserControl TextBoxText="{TemplateBinding TextBoxText}"/&gt;
                  &lt;/StackPanel&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  &lt;Style TargetType="local:CountDisplayControl"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="local:CountDisplayControl"&gt;
                  &lt;Border Background="{TemplateBinding Background}"
                          BorderBrush="{TemplateBinding BorderBrush}"
                          BorderThickness="{TemplateBinding BorderThickness}"&gt;
                      &lt;StackPanel&gt;
                          &lt;sdk:Label Content="Control1"/&gt;
                          &lt;sdk:Label Content="{TemplateBinding Count}"/&gt;
                          &lt;sdk:Label x:Name="labelText" Content="{TemplateBinding Text}"/&gt;
                          &lt;sdk:Label Content="TemplateBinding TextBoxText of CountDisplayControl"/&gt;
                          &lt;TextBox Text="{TemplateBinding TextBoxText}"/&gt;
                      &lt;/StackPanel&gt;
                  &lt;/Border&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  &lt;Style TargetType="local:CountDisplayControl2"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="local:CountDisplayControl2"&gt;
                  &lt;Border Background="{TemplateBinding Background}"
                          BorderBrush="{TemplateBinding BorderBrush}"
                          BorderThickness="{TemplateBinding BorderThickness}"&gt;
                      &lt;StackPanel&gt;
                          &lt;sdk:Label Content="Control2"/&gt;
                          &lt;sdk:Label Content="{TemplateBinding Count}"/&gt;
                          &lt;sdk:Label x:Name="labelText" Content="{TemplateBinding Text}"/&gt;
                          &lt;sdk:Label Content="TemplateBinding TextBoxText of CountDisplayControl2"/&gt;
                          &lt;TextBox Text="{TemplateBinding TextBoxText}"/&gt;
                      &lt;/StackPanel&gt;
                  &lt;/Border&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>