Forum Xamarin.Forms

How to Force MainPage/ContentPage Sizing?

alaskanroguealaskanrogue USMember ✭✭✭
edited February 2017 in Xamarin.Forms

I have created both CalculateScalingFactors and ScalePage methods for my content pages for use with NavigationPage which set both HeightRequest and WidthRequest attributes for the page and all of its visual elements and then set IsVisible and call ForceLayout() on the page. Although the page appears, it is blank. When I look at the instance values of the ContentPage, the HeightRequest and WidthRequest values are set, but both Height and Width are set to -1.

//contentpage

        InitializeComponent();
        NavigationPage.SetHasNavigationBar(this, false);
        CalculateScalingFactors();
        ScalePage();
        IsVisible = true;
        ForceLayout();

//mainpage

        MainPage = new NavigationPage(splash);
        MainPage.IsVisible = true;
        MainPage.ForceLayout();

Looking at the instance values of the MainPage, the HeightRequest / WidthRequest / Height / Width are set to -1. I would think the later two would have been set from the ContentPage.

I have even went a extra step and set the HeightRequest and WidthRequest of the MainPage trying to make the page visible. It doesn't make any difference; no luck. The Height and Width remain -1 after the ForceLayout...

//mainpage

        MainPage = new NavigationPage(splash);
        MainPage.HeightRequest = splash.HeightRequest;
        MainPage.WidthRequest = splash.WidthRequest;
        MainPage.IsVisible = true;
        MainPage.ForceLayout();

Am I missing something? What is really interesting is that it was working back in early December...

Sign In or Register to comment.