WinUI 3标题栏图标

编程语言 2026-07-09

为什么在Visual Studio中运行应用时图标会出现,但从商店下载应用并在Windows下运行时,图标却不出现?我是不是弄错了什么?

private AppWindow MyAppWindow;

if (AppWindowTitleBar.IsCustomizationSupported())
{
    if (MyAppWindow is null)
    {
        MyAppWindow = GetAppWindowForCurrentWindow();
    }

    MyAppWindow.Closing += OnClosing;
    MyAppWindow.SetIcon("Images/Quadrato01.ico");
    MyAppWindow.TitleBar.IconShowOptions = IconShowOptions.ShowIconAndSystemMenu;
}

解决方案

就此而言,这是我在winui3中为我创建的每个窗口的“构造函数”里使用的顺序(我的应用是多窗口的)。

string iconAsset = "Assets/xxx.ico";

this.AppWindow.SetTaskbarIcon( iconAsset );
this.AppWindow.SetTitleBarIcon( iconAsset );
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章