microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.8k stars 320 forks source link

Taskbar badge does not show until the app window closed #3928

Open HO-COOH opened 11 months ago

HO-COOH commented 11 months ago

Describe the bug

I am using Windows.UI.Notification.BadgeUpdateManager api to add a badge to taskbar icon for a winui3 app, the badge does not appear in the taskbar icon until the window is closed. And it will disappear after it launches. In short, it seems that a winui3 app cannot show the badge when the app window is running.

For UWP app however, badge will appear as soon as the function is called.

Steps to reproduce the bug

  1. Use following code

    
    inline auto MakeBadgeNotification(wchar_t const* glyph)
    {
        auto xml = winrt::Windows::UI::Notifications::BadgeUpdateManager::GetTemplateContent(
            winrt::Windows::UI::Notifications::BadgeTemplateType::BadgeGlyph
        );
        xml.SelectSingleNode(L"/badge")
            .as<winrt::Windows::Data::Xml::Dom::XmlElement>()
            .SetAttribute(L"value", glyph);
        return winrt::Windows::UI::Notifications::BadgeNotification{ xml };
    }
    
    inline auto MakeBadgeNotification(int value)
    {
        auto xml = winrt::Windows::UI::Notifications::BadgeUpdateManager::GetTemplateContent(
            winrt::Windows::UI::Notifications::BadgeTemplateType::BadgeNumber
        );
        xml.SelectSingleNode(L"/badge")
            .as<winrt::Windows::Data::Xml::Dom::XmlElement>()
            .SetAttribute(L"value", winrt::to_hstring(value));
        return winrt::Windows::UI::Notifications::BadgeNotification{ xml };
    }

winrt::Windows::UI::Notifications::BadgeUpdateManager::CreateBadgeUpdaterForApplication().Update(MakeBadgeNotification(1)); //number badge winrt::Windows::UI::Notifications::BadgeUpdateManager::CreateBadgeUpdaterForApplication().Update(MakeBadgeNotification(L"alert")); //glyph badge


2. Badge only appears in start menu, not in taskbar
3. Close the app, the taskbar pinned icon now has badge.

### Expected behavior

_No response_

### Screenshots

This is Winui3 app
![image](https://github.com/microsoft/WindowsAppSDK/assets/42881734/efb65ba5-0767-4cfb-a4e4-416c015a1c84)

After closing the window:
![image](https://github.com/microsoft/WindowsAppSDK/assets/42881734/e0bc511d-0bc5-4663-966a-42505d8dad72)

This is UWP app
![image](https://github.com/microsoft/WindowsAppSDK/assets/42881734/287d5249-709a-41a2-b370-94fa3a617047)

### NuGet package version

Windows App SDK 1.4.2: 1.4.231008000

### Packaging type

Packaged (MSIX)

### Windows version

Windows 10 version 1809 (17763, October 2018 Update)

### IDE

_No response_

### Additional context

_No response_
castorix commented 11 months ago

I tested in C# on Windows 10 22H2 with updateBadgeGlyph from MSDN and it does not seem to work either A workaround can be with ITaskbarList3::SetOverlayIcon A test on Windows 10 :

image image

HO-COOH commented 11 months ago

@castorix That good ol COM api is obviously proven to be working. However, you have to provide the HICON instead of the windows built-in glyph, and it's hard to make it consistent with the design language.

HO-COOH commented 9 months ago

This is bugging the "Your phone" app in windows 10. The number badge just disappear when the app is opened, and re-appear after it's closed. c

HO-COOH commented 7 months ago

UPDATE: This issue does not exist on Windows 11.