How to fix icon not showing in the title bar of a MAUI Blazor Hybrid application (Windows specific)?

Bronsk1y 40 Reputation points
2026-09-18T08:30:23.23+00:00

Image of the title bar:
User's image

Issue: icon isn't showing in the title bar of my application.

Details:

  • My project is a MAUI Blazor Hybrid.
  • My project targets only Windows.
  • My project is running .NET9.
  • The icon is located at "Platforms/Windows/appicon.ico".

Description:

I tried multiple methods to fix the issue:

  1. I tried to set the icon by getting the Window and then using SetIcon method:
        // Platforms/Windows/App.xaml.cs 
		protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            base.OnLaunched(args);
            var window = Microsoft.Maui.Controls.Application.Current?.Windows[0]?.Handler?.PlatformView as Microsoft.UI.Xaml.Window;
            if (window != null)
            {
                var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
                var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hwnd);
                var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
                try
                {
                    appWindow.SetIcon("appicon.ico");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"SetIcon failed: {ex.Message}.");
                }
            }
            else
            {
                Debug.WriteLine("Window is null.");
            }
        }

After running the project with Debug activated, output showed no errors, same as the Developer Tools window.

  1. I tried to set the icon by getting the Window, but instead use SetTitleBar method:
        // Platforms/Windows/App.xaml.cs 
        protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            base.OnLaunched(args);
            var window = Microsoft.Maui.Controls.Application.Current?.Windows[0]?.Handler?.PlatformView as Microsoft.UI.Xaml.Window;

            if (window != null)
            {
                var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
                var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hwnd);
                var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
                var titleBar = new CustomTitleBar();
                window.SetTitleBar(titleBar);
            }
        }

After running the project with Debug activated, no exceptions were thrown.

  1. I tried using ExtendsContentIntoTitleBar:
        // Platforms/Windows/App.xaml.cs 
        protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            base.OnLaunched(args);
            var window = Microsoft.Maui.Controls.Application.Current?.Windows[0]?.Handler?.PlatformView as Microsoft.UI.Xaml.Window;

            if (window != null)
            {
                var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
                var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hwnd);
                var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
                appWindow.TitleBar.ExtendsContentIntoTitleBar = false;
                appWindow.SetIcon("appicon.ico");
            }
        }

When running the project with this code, it creates another title bar, this time with the icon; however it dosen't remove the old one:

User's image

Other files:

  • MauiProgram.cs:
using CommunityToolkit.Maui;
using Microsoft.Extensions.Logging;
namespace NuPack;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .UseMauiCommunityToolkit()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
            });
        builder.Services.AddMauiBlazorWebView();
#if DEBUG
        builder.Services.AddBlazorWebViewDeveloperTools();
        builder.Logging.AddDebug();
#endif
        return builder.Build();
    }
}

  • NuPack.csproj (ignore the name its a subject to change):
  <Project Sdk="Microsoft.NET.Sdk.Razor">
  	<PropertyGroup>
  		<TargetFrameworks>net9.0-windows10.0.19041.0</TargetFrameworks>
  		<OutputType>Exe</OutputType>
  		<RootNamespace>NuPack</RootNamespace>
  		<UseMaui>true</UseMaui>
  		<SingleProject>true</SingleProject>
  		<ImplicitUsings>enable</ImplicitUsings>
  		<EnableDefaultCssItems>false</EnableDefaultCssItems>
  		<Nullable>enable</Nullable>
  		<!-- Display name -->
  		<ApplicationTitle>NuPack</ApplicationTitle>
  		<!-- App Identifier -->
  		<ApplicationId>com.companyname.nupack</ApplicationId>
  		<!-- Versions -->
  		<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
  		<ApplicationVersion>1</ApplicationVersion>
  		<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
  		<WindowsPackageType>None</WindowsPackageType>
  		<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
  		<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
  	</PropertyGroup>
  	<ItemGroup>
  		<!-- Images -->
  		<MauiImage Include="Resources\Images\*" />
  		<!-- Custom Fonts -->
  		<MauiFont Include="Resources\Fonts\*" />
  		<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
  		<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
  	</ItemGroup>
  	<ItemGroup>
  	  <MauiXaml Remove="Platforms\Windows\CustomTitleBar.xaml" />
  	</ItemGroup>
  	<ItemGroup>
  		<PackageReference Include="CommunityToolkit.Maui" Version="11.2.0" />
  		<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
  		<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)" />
  		<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.9" />
  	</ItemGroup>
  	<ItemGroup>
  		<MauiIcon Include="Resources\AppIcon\appicon.svg" />
  	</ItemGroup>
  	<ItemGroup Condition="$(TargetFramework.Contains('windows'))">
  		<Content Include="Platforms\Windows\appicon.ico">
  			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  		</Content>
  	</ItemGroup>
  	<ItemGroup>
  		<Folder Include="Resources\Images\" />
  	</ItemGroup>
  	<ProjectExtensions>
  		<VisualStudio>
  			<UserProperties />
  		</VisualStudio>
  	</ProjectExtensions>
  </Project>
  • App.xaml.cs (NuPack/App.xaml.cs):
  namespace NuPack;
  public partial class App : Application
  {
      public App()
      {
          InitializeComponent();
      }
      protected override Window CreateWindow(IActivationState? activationState)
      {
          var window = new Window(new MainPage())
          {
              Title = "NuPack"
          }; 
          return window;
      }
  }
Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author
Nguyen Dam (WICLOUD CORPORATION) 405 Reputation points Microsoft External Staff Moderator
2026-09-18T09:50:05.52+00:00

Hi @Bronsk1y , thank you for confirming that using the .NET MAUI TitleBar resolved the issue.

To provide some additional context on the solution, it can be incorporated directly into your existing CreateWindow override in App.xaml.cs:

protected override Window CreateWindow(IActivationState? activationState)
{
 return new Window(new MainPage())
 {
	 Title = "NuPack",
	 TitleBar = new TitleBar
	 {
	 Title = "NuPack",
	 Icon = "titlebar_icon.png"
	 }
 };
}

In this setup, titlebar_icon.png can be placed in Resources/Images, which your project already includes as MauiImage resources:

<MauiImage Include="Resources\Images\*" />

The reason this resolves the issue is that Window.TitleBar is the .NET MAUI API for assigning a title bar to a Window, while TitleBar.Icon specifically represents the optional icon displayed in that title bar. The recommended size for the title bar icon is 16×16 pixels.

With this approach, retrieving the native Windows AppWindow and setting its icon separately is unnecessary for this purpose. The previous Windows-specific handling using AppWindow.SetIcon(), SetTitleBar(), and ExtendsContentIntoTitleBar would only need to remain if it is required for other title bar customization.

It is also worth distinguishing TitleBar.Icon from the following setting in your project:

<MauiIcon Include="Resources\AppIcon\appicon.svg" />

MauiIcon defines the application icon used to generate platform-specific app icon resources, whereas TitleBar.Icon controls the icon displayed in the .NET MAUI TitleBar.

For more information, please refer to the .NET MAUI TitleBar documentation.

If you found my explanation was helpful or informative to the solution, I would greatly appreciate it if you could follow this guide so others with the same issue can benefit as well. Thank you. 

Was this answer helpful?

2 people found this answer helpful.

Answer accepted by question author

AI answer

2026-09-18T08:30:54.81+00:00

For a .NET MAUI app on Windows, there are two different icon scenarios in the provided material:

  1. App icon for the MAUI app package: set with <MauiIcon> in the project file.
  2. Window title bar icon on Windows: set through Windows AppWindow APIs, or through a MAUI TitleBar.

The current project already defines the MAUI app icon correctly:

<MauiIcon Include="Resources\AppIcon\appicon.svg" />

That is the app icon source for .NET MAUI. .NET MAUI can generate platform assets from that single icon definition.

For the Windows title bar icon, the Windows API shown in the documentation requires AppWindow.SetIcon(String) with a fully qualified path to an .ico file. Passing only:

appWindow.SetIcon("appicon.ico");

is not the documented usage.

Use a full path to the .ico file instead.

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    base.OnLaunched(args);

    var window = Microsoft.Maui.Controls.Application.Current?.Windows[0]?.Handler?.PlatformView as Microsoft.UI.Xaml.Window;
    if (window == null)
        return;

    var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
    var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hwnd);
    var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);

    var iconPath = Path.Combine(AppContext.BaseDirectory, "appicon.ico");
    appWindow.SetIcon(iconPath);
}

Key points for the current behavior:

  • SetIcon(String) works only with .ico files.
  • The path passed to SetIcon(String) must be the fully qualified path.
  • Setting appWindow.TitleBar.ExtendsContentIntoTitleBar = false changes title bar behavior and explains why another title bar appeared. That is not required just to set the icon.

For the duplicate title bar issue, remove this line:

appWindow.TitleBar.ExtendsContentIntoTitleBar = false;

If the goal is only to show the standard Windows title bar icon, use SetIcon(...) and do not switch title bar modes.

Also, if using a MAUI TitleBar, MAUI supports setting the title bar icon directly:

Window window = new Window
{
    TitleBar = new TitleBar
    {
        Icon = "titlebar_icon.png",
        Title = "NuPack"
    }
};

That is a separate approach from AppWindow.SetIcon. Mixing custom title bar handling with Windows title bar APIs can lead to the kind of visual result shown in the screenshot.

A clean fix path for this project is:

  1. Keep the app icon in the project file with:
       <MauiIcon Include="Resources\AppIcon\appicon.svg" />
    
  2. Keep the Windows .ico file copied to output, as already configured.
  3. In OnLaunched, call appWindow.SetIcon(...) with the full path.
  4. Remove ExtendsContentIntoTitleBar = false.
  5. Do not call window.SetTitleBar(...) unless intentionally building a custom title bar.

If different icons are needed per platform, .NET MAUI supports conditional <MauiIcon> items, and only the first valid <MauiIcon> item is used.

AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.