Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting window size on desktop for a Windows 10 UWP app

I've just started learning UWP app development on Windows 10 Pro using Visual Studio 2015 Community Edition. I tried to modify the C# version of the official "Hello, World!" sample by setting the Width and Height attributes of the Page tag in MainPage.xaml.

Interestingly, when I start the app, its size will be different. Moreover, if I resize its window and then restart it, the app seems to remember its previous window size.

Is it possible to force a UWP app to have a predefined window size, at least on desktop PCs?

like image 588
kol Avatar asked Aug 07 '15 20:08

kol


People also ask

How do I make the UWP app full screen?

So here's the big reveal: you can easily full screen almost any UWP apps in Windows 10 just by hitting `Shift + Win + Enter` after focusing a UWP app. The shortcut should work with most UWP apps in Windows 10, but it may not work if an app doesn't allow the window to be maximized in the first place.

How do I size a window preset?

Press Alt + Space shortcut keys together on the keyboard to open the window menu. Now, press S. The mouse cursor will turn into a cross with arrows. Use the left, right, up and down arrow keys to resize your window.

How do I find the window size in Windows 10?

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 .


1 Answers

Try setting PreferredLaunchViewSize in your MainPage's constructor like this:

public MainPage() {     this.InitializeComponent();      ApplicationView.PreferredLaunchViewSize = new Size(480, 800);     ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize; } 

As @kol also pointed out, if you want any size smaller than the default 500x320, you will need to manually reset it:

ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(200, 100)); 
like image 149
Justin XL Avatar answered Sep 19 '22 08:09

Justin XL