question

Dave-1212 avatar image
0 Votes"
Dave-1212 asked KyleWang-MSFT commented

How to Autosize a container like Grid on navigating away, change window size and navigate back on UWP?

I have a landing page that has a Grid to layout various visual elements. All works fine as expected when resizing the window on UWP.
If however I navigate away from that page, change the window bounds (width and height) and navigate back to the first page, the container doesn't autosize to the new ContentPage bounds. Sorry, this looks like an elementary question and only came up for UWP as there is a need to resize the window size.

Landing page: A Grid as child of ContentPage with HorizontalOptions and VerticalOptions and FillAndExpand; assume size is (1024, 600) on a screen size of, say, (1920,1080).

Navigate away and back: Set the page navigated to any size other than (1024, 600) and then navigate back.
Issue: The Landing Page Grid doesn't adjust to the new page bounds while ContentPage assumes the new size. Grid (and its contents) therefore look odd as zoomed in or out.

Is it possible that containers like the Grid can autosize in such scenario? Or, do I need to use some coding for autosizing?




dotnet-xamarin
· 1
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.

anonymous user-1212 Test in Xamarin Forms 5, and the "autosize" works fine. Here is my demo. You can test on your PC. If possible, you can provide a reproducible example via GIthub or Onedrive.
MainPage.xaml

 <Grid HorizontalOptions="FillAndExpand"
         VerticalOptions="FillAndExpand"
         RowDefinitions="*,*,*,*"
         ColumnDefinitions="*,*,*">
     <Label Text="11111111111111111111111111111"/>
     <Label Grid.Row="1" Grid.Column="1" Text="22222222222222222222222222222"/>
     <Label Grid.Row="2" Grid.Column="2" Text="33333333333333333333333333333"/>
     <Button Grid.Row="3" Text="Goto" Clicked="Button_Clicked"/>
 </Grid>

MainPage.xaml.cs

 private void Button_Clicked(object sender, EventArgs e)
 {
     this.Navigation.PushAsync(new SecondPage());
 }
0 Votes 0 ·

0 Answers