Hello,
For the case of hiding and redisplaying the rows and columns of the Grid, it is recommended that you remove/add rows and columns instead of hiding them.
This is because after the rows and columns are compressed and hidden, the space occupied needs to be recalculated when they are redisplayed. This will cause the width and height of the layout to be incorrectly distributed in some cases.
Please refer to the following workaround:
private void Button_Clicked(object sender, EventArgs e)
{
myGrid.RowDefinitions.RemoveAt(2);
myGrid.ColumnDefinitions.RemoveAt(2);
}
private async void Button_Clicked_1(object sender, EventArgs e)
{
myGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
myGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
}
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.