在Windowsapp store中获取窗口宽度/高度

我目前有一个加载的基本页面,我需要一些方法来获取窗口的宽度和高度,最好是在构造函数中。 问题是,在构造函数中,或者在页面完全加载之前,我似乎无法掌握宽度和高度。 加载后我可以使用:

this.ActualWidth; this.ActualHeight; 

是否有任何窗口加载完成事件我可以使用或以任何方式获得加载过程中的宽度和高度?

您可以使用属性Window.Current.Bounds随时查找窗口的大小。 有关更多详细信息,请阅读: 如何获得屏幕分辨率? 对于WinRT应用程序?

这是一篇关于如何处理SizeChanged事件的博客文章。 如果不执行此类操作,则无法获取ActualWidth / ActualHeight,因为它们是在呈现控件时计算的。

 private void OnWindowSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e) { var CurrentViewState = Windows.UI.ViewManagement.ApplicationView.Value; double AppWidth = e.Size.Width; double AppHeight = e.Size.Height; // DownloadImage requires accurate view state and app size! DownloadImage(CurrentViewState, AppHeight, AppWidth); } Window.Current.SizeChanged += OnWindowSizeChanged;