在桌面上为 Windows 10 UWP 应用设置窗口大小 [英] Setting window size on desktop for a Windows 10 UWP app

查看:28
本文介绍了在桌面上为 Windows 10 UWP 应用设置窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 Visual Studio 2015 社区版在 Windows 10 专业版上学习 UWP 应用开发.我尝试修改了C#版本的官方Hello, World!"示例 通过在 MainPage.xaml 中设置 Page 标记的 WidthHeight 属性.

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.

是否可以强制 UWP 应用程序具有预定义的窗口大小,至少在台式机上是这样?

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

推荐答案

尝试在你的 MainPageconstructor 中设置 PreferredLaunchViewSize 像这样:

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

public MainPage()
{
    this.InitializeComponent();

    ApplicationView.PreferredLaunchViewSize = new Size(480, 800);
    ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
}

正如@kol 还指出的,如果您想要任何小于默认 500x320 的尺寸,您需要手动重置它:

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));

这篇关于在桌面上为 Windows 10 UWP 应用设置窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆