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?
Try setting
PreferredLaunchViewSize
in yourMainPage
's constructor like this.Update
As @kol also pointed out, if you want any size smaller than the default 500x320, you will need to manually reset it.
For the very first app launch, the
ApplicationView.PreferredLaunchWindowingMode
is set toApplicationViewWindowingMode.Auto
regardless of what you set in your code.However, from this question on MSDN, there may be a way to overcome this. One of the answers gives a way to set that very first launch size (reverting to
Auto
after that).P.S. I have not tested this.
Hi I have solution to your problem, the thing is that you don't really have control over the window size, and even if you will try to re-size it it may fail. I've asked the same question on msdn forums and got the answer here
https://social.msdn.microsoft.com/Forums/en-US/3110e17d-b7c8-4040-8e25-a27df7595f13/windows-10-universal-directx-application?forum=wpdevelop
btw here is the solution in your event handler "OnLaunched" or in your Event Handler "OnActivated" find:
And replace it with:
It is better if you place this code into "OnActivated()" event handler as it will set your defined size when app starts and when it become Active after any interruptions.
In "desiredSize" Calculation 800 is width and 600 is height this calculation is needed because size is in DPI so you have to convert it from pixels to DPI
Also keep in mind that size cannot be smaller than "320x200"