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

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

问题描述

我刚刚开始使用Visual Studio 2015 Community Edition在Windows 10 Pro上学习UWP应用开发。我尝试修改官方 Hello,World!的C#版本。通过在MainPage.xaml中设置Page标记的 Width Height 属性

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?

推荐答案

尝试在 PreferredLaunchViewSize 中设置您的 MainPage 构造函数如下:

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天全站免登陆