由于某种原因,我需要在页面构造函数中获取设备屏幕高度并使用它来设置其他页面项目的大小。我这样做:

double screenHeight = Application.Current.RootVisual.RenderSize.Height;

但是,我最近发现,如果应用程序退出逻辑删除并且此页面是活动页面,则此代码会失败。在这种情况下, Application.Current.RootVisual 一片空白。

如何克服这个问题,或者有其他方法来获取屏幕高度?

有帮助吗?

解决方案

实际上, Application.Current.RootVisual.RenderSize 返回屏幕分辨率。如果这就是您想要的,请使用 Application.Current.Host.Content.ActualHeight 反而:

double screenHeight = Application.Current.Host.Content.ActualHeight;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top