For some reason, I need to get the device screen height in the page constructor and use it to set the sizes of other page items. I do it like this:
double screenHeight = Application.Current.RootVisual.RenderSize.Height;
However, I've recently detected that this code fails if the app comes out of tombstoning and this page is the active page. In this case, Application.Current.RootVisual
is null.
How to overcome this, or are there other methods to get the screen height?
Actually, Application.Current.RootVisual.RenderSize
returns screen resolution. If that is what you want, use Application.Current.Host.Content.ActualHeight
instead:
double screenHeight = Application.Current.Host.Content.ActualHeight;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.