Get window width and height in windows store apps

Currently, I have a base page that loads, and I need a way to get the width and height of the window, preferably in the constructor. The problem is that in the designer or before the page is fully loaded, I cannot get the width and height. After loading, I can simply use:

this.ActualWidth; this.ActualHeight; 

Is there any window loading completion event that I can use, or any way to get the width and height at boot time?

+6
source share
2 answers

You can find out the size of the window at any time using the Window.Current.Bounds property. For more information read: How to get screen resolution? For the WinRT application?

+7
source

Here is a blog post on how to handle the SizeChanged event. You cannot get ActualWidth / ActualHeight without doing something like this, because they are computed 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; 
+3
source

Source: https://habr.com/ru/post/927762/


All Articles