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

Lucky B.C 51 Reputation points
2022-06-16T11:38:47.767+00:00

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;  
Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,320 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lucky B.C 51 Reputation points
    2022-06-16T16:11:13.423+00:00

    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>  
    	  
    
    1 person found this answer helpful.
    0 comments No comments