简体   繁体   中英

Get screen height in WP8 Silverlight app on page initialization after tombstoning

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM