WinUI 3本身未提供任务视图图标接口,可通过WinUI.WinUIEx包实现。下列代码省略命名空间声明;Constants.AssetsPath.IconPath为图标路径。

方法1:使用Microsoft.UI.Xaml.Window类

using Microsoft.UI.Xaml;
using WinUIEx;

public sealed partial class MainWindow : Window
{
    private IntPtr WindowHandle { get; }
    public MainWindow()
    {
        WindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);

        this.InitializeComponent();

        HwndExtensions.SetIcon(WindowHandle, Constants.AssetsPath.IconPath);
    }
}

方法2:使用WinUIEx.WindowEx类

using Microsoft.UI.Xaml;
using WinUIEx;

public sealed partial class MainWindow : WindowEx
{
    public MainWindow()
    {
        this.InitializeComponent();
        AppWindow.SetIcon(Constants.AssetsPath.IconPath);
    }
}