I currently have a basic page which loads, and I need some way of obtaining the width and height of the window, preferably in the constructor. The problem is, in the constructor, or before the page is completely loaded, I can't seem to get hold of the width and height. After it is loaded I can just use:
this.ActualWidth;
this.ActualHeight;
Is there any window load complete event I can use or any way to obtain the width and height during the loading?
You can find out the size of the Window at any moment using the property Window.Current.Bounds . For more details, read: How to get the resolution of screen? For a WinRT app?
Here is a blog post on how to handle the SizeChanged
event. You can't get the ActualWidth/ActualHeight without doing something like this because they are calculated when the control is rendered.
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;
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.