title: how to access label name in nested listview datatemplate on a check box event
body: <p>I have defined a label with name and I'm trying to access it but no luck. Let me explain my problem with my code.</p>
  
  <pre><code>   &lt;ListView Name="gridListView" ItemsSource="{Binding... }"&gt;
              &lt;ListView.ItemContainerStyle&gt;
                  &lt;Style TargetType="ListViewItem"&gt;
                      &lt;Setter Property="Focusable" Value="false"/&gt;
                  &lt;/Style&gt;
              &lt;/ListView.ItemContainerStyle&gt;
          &lt;ListView.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Border&gt;
                      &lt;StackPanel Orientation="Vertical"&gt;
                          &lt;Label x:Name="vLabel" Content="{Binding VCValue}"/&gt;
                          &lt;ListView Name="checkBoxListView" ItemsSource="{Binding CList}"&gt;
                              &lt;ListView.ItemTemplate&gt;
                                  &lt;DataTemplate&gt;
                                      &lt;CheckBox Margin="5" Click="CheckBox_Click" IsChecked="{Binding SelectedValue, Mode=TwoWay}"  Content="{Binding Current, Mode=OneWay }"/&gt;
                                  &lt;/DataTemplate&gt;
                              &lt;/ListView.ItemTemplate&gt;
                          &lt;/ListView&gt;
                      &lt;/StackPanel&gt;
                  &lt;/Border&gt;
              &lt;/DataTemplate&gt;
          &lt;/ListView.ItemTemplate&gt;
      &lt;/ListView&gt;
  </code></pre>
  
  <p>In the above code, I have two listview, gridListView and checkBoxListView. Here, I want to access the label vLabel which is inside the datatemplate of gridListView when the one of the value in checkbox(which is inside checkBoxListView) is clicked.
  I understand it can't be accessed directly as its within datatemplate so i tried below code as suggested in other forums but gridListView.SelectedIndex is always -1 so i know i'm not doing the right thing. When I just hardcoded gridListView.SelectedIndex to index 0, 1 or 2 its giving me the right value of vLabel so the below code will work if gridListView.SelectedIndex is correct.</p>
  
  <pre><code>private void CheckBox_Click(object sender, RoutedEventArgs e)
      {
          CheckBox chk =(CheckBox)sender;
          int index = gridListView.Items.IndexOf(chk.DataContext);
          ListViewItem item = gridListView.ItemContainerGenerator.ContainerFromIndex(gridListView.SelectedIndex) as ListViewItem;
          if (item!=null)
          {
              //get the item's template parent
              ContentPresenter templateParent = GetFrameworkElementByName&lt;ContentPresenter&gt;(item);
              DataTemplate dataTemplate = gridListView.ItemTemplate;
              if (dataTemplate != null &amp;&amp; templateParent != null)
              {
                  var lab = dataTemplate.FindName("vLabel", templateParent) as Label;
                  var v = lab.Content;
              }
          }   
  
  private static T GetFrameworkElementByName&lt;T&gt;(FrameworkElement referenceElement) where T : FrameworkElement
      {
       //I can post this function if need be
         ....
      }
  </code></pre>
  
  <p>Appreciate any help that will help me access vLabel.</p>
  
  <p>Thanks in advance</p>