title: Accessing ListView within an ItemTemplate
body: <p>I have an ItemsControl that is bound to a list of Objects.
  I have an ItemTemplate set for the ItemsControl... and within the ItemTemplate I have a ListView, which I want to bind to another list of Objects.</p>
  
  <p>How do I gain access to the ListView within the ItemsControl.ItemTemplate so that I can set it's DataContext to the second list of objects?</p>
  
  <p>Here is an example of what I have:</p>
  
  <pre><code>                &lt;ItemsControl x:Name="DealerShips" ItemsSource="{Binding}"&gt;
                      &lt;ItemsControl.ItemTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;Expander Header="{Binding Name}" Foreground="White"&gt;
                                  &lt;ListView x:Name="CarTypes" ItemsSource="{Binding}"&gt;
                                      &lt;ListView.ItemTemplate&gt;
                                          &lt;CheckBox Content="{Binding Path=Name}" IsChecked="{Binding Path=InStock}"&gt;&lt;/CheckBox&gt;
                                      &lt;/ListView.ItemTemplate&gt;
                                  &lt;/ListView&gt;
                              &lt;/Expander&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/ItemsControl.ItemTemplate&gt;
                  &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>In my VB.NET code I can refer to my "DealerShips" ItemsControl to set the DataContext to a List(Of DealerShip) Objects. I can't figure out how to gain access to the "CarTypes" ListView so that I can set it's DataContext.</p>
  
  <pre><code>Public Class CarsWindow
      Private _listOfDealerShips As ObservableCollection(Of DealerShip)
      Private _listOfInventory As ObservableCollection(Of Car)
  
    Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
          _listOfDealerShips = New ObservableCollection(Of DealerShip)
          listOfDealerShips.Add(New DealerShip("A"))
          listOfDealerShips.Add(New DealerShip("B"))
          listOfDealerShips.Add(New DealerShip("C"))
  
          _listOfInventory = New ObservableCollection(Of Cars)
          listOfDealerShips.Add(New Car("TypeX",True))
          listOfDealerShips.Add(New Car("TypeY",False))
          listOfDealerShips.Add(New Car("TypeZ",True))
  
          DealerShips.DataContext = _listOfDealerShips
  
          ' I cannot access CarTypes....
          'CarTypes.DataContext = listOfInventory 
    End Sub
  
    Private Class DealerShip
      Public Property Name As String
      Public Sub New
      End Sub
      Public Sub New(ByVal name As String)
        Me.Name = name
      End Sub
    End Class
  
    Private Class Car
      Public Property Name As String
      Public Property InStock As Boolean
      Public Sub New
      End Sub
      Public Sub New(ByVal name As String, ByVal isInStock As Boolean)
        Me.Name = name
        Me.InStock = isInStock 
      End Sub
    End Class
  End Class
  </code></pre>
  
  <p>Thank you for your help!</p>
  
  <p>-Frinny</p>