title: How to collapse child control in listviewitem UWP
body: <p>Universal Windows Platform, C#</p>
  
  <p>How can I collapse/expand the child listview of item MainListView listitem from code behind? I have not found anything that works.
  I'd like to do this on the SelectionChanged event.</p>
  
  <p>XAML</p>
  
  <pre><code>        &lt;ListView x:Name="DestListView" SelectionMode="Single" Margin="0,60,0,0" SelectionChanged="listview_SelectionChanged" &gt;
          &lt;ListView.ItemContainerStyle &gt;
              &lt;Style TargetType="ListViewItem"&gt;
                  &lt;Setter Property="HorizontalContentAlignment" Value="Stretch" /&gt;
                  &lt;Setter Property="BorderThickness" Value="0,.5,0,0" /&gt;
                  &lt;Setter Property="BorderBrush" Value="Gainsboro" /&gt;
              &lt;/Style&gt;
          &lt;/ListView.ItemContainerStyle&gt;
          &lt;ListView.ItemTemplate &gt;
              &lt;DataTemplate&gt;
                  &lt;StackPanel&gt;
                      &lt;Grid&gt;
                          &lt;Grid HorizontalAlignment="Stretch"&gt;
                              &lt;Grid.ColumnDefinitions&gt;
                                  &lt;ColumnDefinition Width="40"/&gt;
                                  &lt;ColumnDefinition Width="100"/&gt;
                                  &lt;ColumnDefinition Width="50"/&gt;
                                  &lt;ColumnDefinition Width="*"/&gt;
                                  &lt;ColumnDefinition Width="50"/&gt;
                              &lt;/Grid.ColumnDefinitions&gt;
  
                              &lt;CheckBox Grid.Column="0" MinWidth="20" /&gt;
                              &lt;TextBlock Grid.Column="1" Text="{Binding destination}" FontSize="20" /&gt;
                              &lt;TextBlock Grid.Column="2" Text="{Binding total_quantity}" FontSize="20" Margin="10,0,0,0"/&gt;
                              &lt;TextBlock Grid.Column="3" Text="{Binding package_type}" FontSize="20" HorizontalAlignment="Center" Margin="10,0,0,0"/&gt;
                              &lt;TextBlock Grid.Column="4" Text="{Binding total_weight}" FontSize="20" Margin="10,0,0,0"/&gt;
                          &lt;/Grid&gt;
                      &lt;/Grid&gt;
  
                      **&lt;!--Collpase/Expand--&gt;**
  
                      &lt;ListView x:Name="DetailListView" ItemsSource="{Binding destination_data}" SelectionMode="Multiple" Margin="20,0,0,0" Visibility="Collapsed" &gt;
                          &lt;ListView.ItemTemplate &gt;
                              &lt;DataTemplate &gt;
                                  &lt;StackPanel Orientation="Vertical"&gt;
                                      &lt;TextBlock Text="{Binding visual_number}" FontSize="14" Foreground="White" HorizontalAlignment="Stretch" /&gt;
                                    &lt;/StackPanel&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/ListView.ItemTemplate&gt;
                      &lt;/ListView&gt;
  
                  &lt;/StackPanel&gt;
  
              &lt;/DataTemplate&gt;
          &lt;/ListView.ItemTemplate&gt;
      &lt;/ListView&gt;
  </code></pre>
  
  <p>CodeBehind</p>
  
  <pre><code>     private void listview_SelectionChanged(object sender, SelectionChangedEventArgs e)
      {
          //GET THE ITEM
          var selectItem = DestListView.Items[DestListView.SelectedIndex];
  
          //GET THE CHILD SOMEHOW
          //ListView childListView = (ListView)...not sure what to do here
  
          //if (childListView != null)
          //{
          //    if (childListView.Visibility == Visibility.Collapsed)
          //    {
          //        //childListView.Visibility = Visibility.Collapsed;
          //    }
          //    else
          //    {
          //        //childListView.Visibility = new Visibility;
          //    }
          //}
  
      }
  </code></pre>