[英]Windows 10 Universal app screen size on launch not working
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 并且首先尝试了MainPage.xaml.cs的构造函数中的代码片段(无效),然后在上方
Window.Current.Activate();
In App.xaml.cs which also didn't work. 在App.xaml.cs中也不起作用。 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. 在App.xaml.cs中的Window.Current.Activate之后和MainPage.xaml.cs中的构造函数的末尾。
I did notice that in MainPage.xaml.cs, I could do: 我确实注意到在MainPage.xaml.cs中,我可以这样做:
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. 确实可以正确调整窗口内MainPage框架的大小,但是整个Window保持相同的大小。
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! 谢谢!
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(); 在Window.Current.Activate();之前在App.xaml.cs中调用此函数;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.