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

如何实现UWP应用启动时最大化显示并始终显示带按钮的标题栏

UWP应用启动时最大化并始终显示标题栏的解决方案

你当前使用的ApplicationViewWindowingMode.FullScreen是全屏模式,该模式的默认特性就是自动隐藏标题栏,仅在鼠标悬停顶部时才会唤起。要实现「启动时最大化窗口+始终显示带最小化/关闭按钮的标题栏」,需要调整窗口模式并显式设置标题栏可见性,具体修改如下:

核心修改步骤

  • 替换全屏模式为最大化模式:Windows 10 1809(版本17763)及以上支持直接设置Maximized模式;若需兼容更早版本,可手动指定启动窗口尺寸为屏幕工作区大小。
  • 强制标题栏始终可见:通过API显式关闭标题栏的自动隐藏逻辑。

修改后的完整代码

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    Frame rootFrame = Window.Current.Content as Frame;
   
    if (rootFrame == null)
    {
        rootFrame = new Frame();
        Window.Current.Content = rootFrame;
    }
    mDispatcher = rootFrame.Dispatcher;

    // 替换全屏模式为最大化模式(适用于Windows 10 1809及以上)
    ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Maximized;

    // 显式设置标题栏始终可见
    var currentView = ApplicationView.GetForCurrentView();
    currentView.TitleBar.IsVisible = true;

    // 兼容旧版Windows 10的备选方案(替换上面的Maximized设置)
    // ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
    // var screenBounds = Window.Current.Bounds;
    // ApplicationView.PreferredLaunchViewSize = new Size(screenBounds.Width, screenBounds.Height);

    // 必须确保窗口激活,否则可能无法正常显示
    Window.Current.Activate();
}

额外说明

  • 如果你的应用开启了ExtendViewIntoTitleBar = true(自定义标题栏样式),需要自行在UI中添加最小化、关闭按钮,否则系统默认按钮会被隐藏;若无需自定义标题栏,保持该属性为默认的false即可,系统会自动显示标准标题栏及按钮。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 14:40:33