title: WPF Basics: How to set an outside property in a DataTrigger?
body: <p>I"m trying to get my head wrapped around the WPF model.</p>
  
  <p>I have a list box of items. Inside the list box items are string identifiers. This works fine. What I want is to have it so that the identifier from the currently selected item is accessible in my code-behind for the enclosing control.</p>
  
  <p>I have this:</p>
  
  <pre><code>&lt;ListBox.ItemTemplate&gt;
   &lt;DataTemplate&gt;
     &lt;StackPanel Width="320"&gt;
      &lt;Label Content="{Binding Path=ShortName}" Style="{StaticResource ListHeader}"/&gt;
        &lt;TextBlock TextWrapping="Wrap" Text="{Binding Path=Description}" Style="{StaticResource ListText}" /&gt;
     &lt;/StackPanel&gt;
   &lt;/DataTemplate&gt;
   &lt;/ListBox.ItemTemplate&gt;
  </code></pre>
  
  <p>And I think I should add something like:</p>
  
  <pre><code>&lt;DataTemplate.Triggers&gt;
      &lt;DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True"&gt;
      &lt;Setter Property="" TargetName=""&gt;
       &lt;Setter.Value&gt;
  
       &lt;/Setter.Value&gt;
     &lt;/Setter&gt;
   &lt;/DataTrigger&gt;
  </code></pre>
  
  <p></p>
  
  <p>But I'm lost as to how to set-up the setter to set a property that's part of the enclosing control (ie, the outside world). I think I have this backwards somehow?</p>