title: How do I bind to the SelectedItem property in a ControlTemplate?
body: <p>Consider the following Control/Template</p>
  
  <pre><code>&lt;my:ExpandingListBox Margin="0,2,0,0" x:Name="TagSearchListBox"&gt;
      &lt;my:ExpandingListBox.Template&gt;
          &lt;ControlTemplate TargetType="{x:Type my:ExpandingListBox}"&gt;
              &lt;Border Name="MyBorder" BorderThickness="2" BorderBrush="Black"&gt;
                  &lt;Grid&gt;
                      &lt;TextBlock Name="MySelectionInfo" Background="White" Text="{TemplateBinding SelectedItem}"/&gt;
                      &lt;ScrollViewer Name="MyScrollViewer" HorizontalScrollBarVisibility="Hidden" Opacity="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" VerticalScrollBarVisibility="Hidden"&gt;
                          &lt;ItemsPresenter Name="MyItemsPresenter"/&gt;
                      &lt;/ScrollViewer&gt;
                  &lt;/Grid&gt;
              &lt;/Border&gt;
          &lt;/ControlTemplate&gt;
      &lt;/my:ExpandingListBox.Template&gt;
  &lt;/my:ExpandingListBox&gt;
  </code></pre>
  
  <p>Basically, there are additional triggers/resources that cause the control to expand/collapse when IsMouseOver is true. When the control is collapsed, I'd like the TextBlock "MySelectionInfo" to display the selected item's text; when it's expanded, I'd like the list of items to be displayed like normal. Is there a way to grab the selected item's text and display it in the TextBlock in pure XAML? </p>
  
  <p>Setting Text="{TemplateBinding SelectedItem}" runs, but doesn't display anything.</p>
  
  <p><strong>EDIT (Solution):</strong></p>
  
  <pre><code>&lt;TextBlock Name="MySelectionInfo" Background="White"&gt;
      &lt;TextBlock.Text&gt;
          &lt;Binding Path="SelectedItem.Name"&gt;
              &lt;Binding.RelativeSource&gt;
                  &lt;RelativeSource Mode="FindAncestor" AncestorType="{x:Type my:ExpandingListBox}"/&gt;
              &lt;/Binding.RelativeSource&gt;
          &lt;/Binding&gt;
      &lt;/TextBlock.Text&gt;
  &lt;/TextBlock&gt;
  </code></pre>
  
  <p>".Name" is a known property of the type of item I'm displaying.</p>