Reputation: 1814
I had read a ton about setting the app window size on launch. Basically, my app is launching full screen everytime. I want to restrict it to a pre-defined size when it launches. However, nothing seems to be working. Here is what I have done so far:
I have put the following:
var desiredSize = new Size(400, 600);
ApplicationView.GetForCurrentView().ExitFullScreenMode();
ApplicationView.GetForCurrentView().SetPreferredMinSize(desiredSize);
ApplicationView.PreferredLaunchViewSize = desiredSize;
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
And have tried that snippet in first the constructor for MainPage.xaml.cs (which didn't work), then just above
Window.Current.Activate();
In App.xaml.cs which also didn't work. Based on some reading, I also tried adding:
ApplicationView.GetForCurrentView().TryResizeView(desiredSize);
Both after Window.Current.Activate in App.xaml.cs and at the end of the constructor in MainPage.xaml.cs.
I did notice that in MainPage.xaml.cs, I could do:
this.Width = 400;
this.Height = 600;
And that does work to size the MainPage frame within the window properly but the overall Window stays the same size.
I can manually drag the window to the size I want after it launches but I want it so simply just launch this size everytime. What am I missing?
Thanks!
Upvotes: 0
Views: 1893
Reputation: 1488
You should set minimum window size if it's less than default
ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size { Width = 400, Height = 600});
ApplicationView.PreferredLaunchViewSize = new Size(400, 600);
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
Call this in App.xaml.cs before Window.Current.Activate();
Upvotes: 1