title: How can I bind inside this ControlTemplate?
body: <p>I have a <code>ListView</code>, filled with a <code>List&lt;MyListItem&gt;</code> and I need to use a <code>ControlTemplate</code> to be able to change the effects when an item is selected. Now I have the problem that <code>{Binding MyProperty}</code> doesn't work inside of that <code>ControlTemplate</code>. How can I access the properties of <code>MyListItem</code> inside the template?</p>
  
  <p>My XAML looks like this(simplified):</p>
  
  <pre><code>&lt;ListView
          Name="ListView"
          Grid.Column="1"
          IsSwipeEnabled="False"&gt;
  
          &lt;ListView.ItemContainerStyle&gt;
              &lt;Style TargetType="ListViewItem"&gt;
                  &lt;Setter Property="Template"&gt;
                      &lt;Setter.Value&gt;
                          &lt;ControlTemplate TargetType="ListViewItem"&gt;
                              &lt;Grid&gt;
                                  &lt;VisualStateManager.VisualStateGroups&gt;
                                      &lt;VisualStateGroup x:Name="CommonStates"&gt;
                                          &lt;VisualState x:Name="Normal"/&gt;
                                      &lt;/VisualStateGroup&gt;
                                      &lt;VisualStateGroup x:Name="SelectionStates"&gt;
                                          &lt;VisualState x:Name="Unselected"&gt;
                                              &lt;Storyboard&gt;
                                                  &lt;ColorAnimation Duration="0" Storyboard.TargetName="myColoredText" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="Orange"/&gt;
                                              &lt;/Storyboard&gt;
                                          &lt;/VisualState&gt;
                                          &lt;VisualState x:Name="SelectedUnfocused"&gt;
                                              &lt;Storyboard&gt;
                                                  &lt;ColorAnimation Duration="0" Storyboard.TargetName="myColoredText" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="Red"/&gt;
                                              &lt;/Storyboard&gt;
                                          &lt;/VisualState&gt;
                                      &lt;/VisualStateGroup&gt;
                                  &lt;/VisualStateManager.VisualStateGroups&gt;
  
                                  &lt;!-- Here I have my custom layout, removed for readability --&gt;
                                  &lt;TextBlock
                                      Name="myColoredText"
                                      Foreground="Green"
                                      Text="{Binding MyProperty}"/&gt;&lt;!-- This does not work --&gt;
  
                              &lt;/Grid&gt;
                          &lt;/ControlTemplate&gt;
                      &lt;/Setter.Value&gt;
                  &lt;/Setter&gt;
              &lt;/Style&gt;
          &lt;/ListView.ItemContainerStyle&gt;
      &lt;/ListView&gt;
  </code></pre>
  
  <p>Here is the class behind this XAML:</p>
  
  <pre><code>public sealed partial class MyPage : Page
  {
      public MyPage()
      {
          InitializeComponent();
          ListView.ItemsSource = new List&lt;MyListItem&gt;()
          {
              new MyListItem("Title1", "SubTitle1"),
              new MyListItem("Title2", "SubTitle2")
          }
      }
  }
  </code></pre>
  
  <p>and the MyListItem class:</p>
  
  <pre><code>class MyListItem
  {
      public string MyProperty { get; set; }
      public string MyOtherProperty { get; set; }
  
      public MyListItem(string myProperty, string myOtherProperty)
      {
          MyProperty = myProperty;
          MyOtherProperty = myOtherProperty;
      }
  }
  </code></pre>
  
  <p>Smallest project with the problem:</p>
  
  <p><a href="https://www.dropbox.com/s/a6bmybghjuq92ek/App3.zip?dl=0" rel="nofollow">Project</a></p>