How to we get a Page's height/width?
I've tried Height, Width, and Bounds but haven't had any luck. Keeps returning -1.
You're probably checking before the layout engine has calculated the positions and sizes of the controls.
And easy way to make sure your page size has been calculated is to handle the SizeChanged EventHander:
private static Page myPage;
public static Page GetMainPage()
myPage = new ContentPage
Content = new Label
Text = "Hello, Forms !",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
myPage.SizeChanged += myPage_SizeChanged;
static void myPage_SizeChanged(object sender, EventArgs e)
Debug.WriteLine(myPage.Width + " " + myPage.Height);
I knew it was something simple. Thanks!
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies