question

LuckyBC-1075 avatar image
0 Votes"
LuckyBC-1075 asked LuckyBC-1075 edited

How to collapse individual nested grids/stackpanels inside a grid?

Hi, I have been trying to collapse 1 of 2 grids inside a grid, but the parent grid always collapses these 2 children grids.

 <Grid x:Name="ParentGrid">
  <Grid x:Name="ChildGrid1">
  </Grid>
    
  <Grid x:Name="ChildGrid2">
  </Grid>
    
 </Grid>
    
    
 ...
 this.ChildGrid1.Visibility = Visibility.collapsed;
dotnet-csharpwindows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LuckyBC-1075 avatar image
1 Vote"
LuckyBC-1075 answered LuckyBC-1075 edited

I think I found out why the ParentGrid collapsed all is that I put the ParentGrid in another Grid that is in a ScrollViewer, but I put the ScrollViewer in another Grid with RowDefinition.Height="Auto". So If I do not use the ScrollViewer, I can make the ChildGrid1 collapses. And If I set the RowDefinition.Height from "Auto" to "*", I can use the ScrollViewer to scroll the content and also make the childGrid1 collapses.


 <Grid x:Name="ParentGrid">
     <Grid.RowDefinitions>
         <RowDefinition Height="Auto"/>
         <RowDefinition Height="*"/>
     </Grid.RowDefinitions>
        
     <Grid Grid.Row="0" x:Name="ChildGrid1">
     </Grid>
        
     <Grid Grid.Row="1" x:Name="ChildGrid2">
     </Grid>
        
 </Grid>
        
        
 ...
 this.ChildGrid1.Visibility = Visibility.collapsed;
        
        
 <Grid>
     <Grid.RowDefinitions>
         <RowDefinition Height="Auto"/>
         <!--RowDefinition Height="Auto"-->
         <RowDefinition Height="*"/> 
     </Grid.RowDefinitions>
        
     <ScrollViewer Grid.Row="1">
         <Grid>
             <Grid.RowDefinitions>
                 <RowDefinition Height="Auto"/>
                 <RowDefinition Height="Auto"/>
             </Grid.RowDefinitions>
            
             <!--An User Control that has the ParentGrid (Grid)-->
             <userControls:MyUserControl Grid.Row="0"/>
             <userControls:MyUserControl2 Grid.Row="1"/>
         </Grid>
     </ScrollViewer>
 </Grid>


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.