You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何缩小UWP应用窗口尺寸?无法调至计算器/记事本大小

解决UWP应用无法调整至更小窗口尺寸的方法

方法1:通过代码设置窗口最小尺寸

在App.xaml.cs的OnLaunched方法(或窗口初始化逻辑处)添加代码,自定义最小宽高:

using Windows.UI.ViewManagement;

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    Frame rootFrame = Window.Current.Content as Frame;

    if (rootFrame == null)
    {
        rootFrame = new Frame();
        rootFrame.NavigationFailed += OnNavigationFailed;
        Window.Current.Content = rootFrame;
    }

    if (e.PrelaunchActivated == false)
    {
        if (rootFrame.Content == null)
        {
            rootFrame.Navigate(typeof(MainPage), e.Arguments);
        }
        // 自定义最小窗口尺寸,示例为200x300,可按需修改
        ApplicationView.GetForCurrentView().SetPreferredMinSize(new Windows.Foundation.Size(200, 300));
        Window.Current.Activate();
    }
}

注意:UWP系统有最低尺寸限制,不能小于192x48(宽×高),若设置值低于该限制,系统会自动采用最低标准。

方法2:修改应用清单配置

打开项目的Package.appxmanifest文件(右键项目→选择「打开方式」→「XML(文本)编辑器」),添加或调整窗口尺寸相关节点:

<Applications>
  <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="YourAppName.App">
    <uap:VisualElements DisplayName="YourAppName" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="YourAppDescription" BackgroundColor="transparent">
      <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" Square310x310Logo="Assets\Square310x310Logo.png" Square71x71Logo="Assets\Square71x71Logo.png" />
      <uap:SplashScreen Image="Assets\SplashScreen.png" />
      <!-- 配置初始窗口尺寸与最小尺寸 -->
      <uap:InitialWindowSize Width="500" Height="600" />
      <uap:PreferredMinWidth>200</uap:PreferredMinWidth>
      <uap:PreferredMinHeight>300</uap:PreferredMinHeight>
    </uap:VisualElements>
  </Application>
</Applications>

保存后重新编译应用,即可按设置的最小尺寸调整窗口。

额外说明

  • 若使用WinUI 3桌面打包版UWP,设置逻辑一致,在App.xaml.cs的OnLaunched方法中调用ApplicationView.GetForCurrentView().SetPreferredMinSize即可。
  • 只要设置值不低于系统最低限制,上述方法均可生效。

内容的提问来源于stack exchange,提问作者DeeJay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 02:15:31