Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get window width / height in Windows store apps

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?

like image 256
ptf Avatar asked Oct 15 '12 15:10

ptf


People also ask

How to get application window size?

If you want the size of your app's window you can just call yourview. getHeight() and yourview. getWidth(); But the view must be drawn for that to work. There are a lot of different cases of screen/view measurement though, so if you could be more specific about "actual size of applications window", is this your app?

How do I make Windows 10 apps smaller?

Press Alt + Spacebar to open the window's menu. If the window is maximized, arrow down to Restore and press Enter . Press Alt + Spacebar again to open the window menu, arrow down to Size, and press Enter .

How do I change the window size in Visual Studio?

Select the form, then find the Properties pane in Visual Studio. Scroll down to size and expand it. You can set the Width and Height manually.


2 Answers

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?

like image 99
Mike Boula Avatar answered Sep 24 '22 20:09

Mike Boula


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;
like image 27
N_A Avatar answered Sep 25 '22 20:09

N_A