lepoco / lepoco/wpfui

Changing `NotifyIcon.Icon` for a registered `NotifyIcon` does not work

Open
#408 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
9.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

Changing NotifyIcon.Icon for a registered NotifyIcon does not work.

The icon on the tray remains the default app icon.

To Reproduce
using WinIcon = System.Drawing.Icon;

    private static WinIcon? GetIcon(string fileName)
    {
        return WinIcon.ExtractAssociatedIcon(fileName);
    }

    private static ImageSource? GetIconImage(string fileName)
    {
        using var icon = GetIcon(fileName);
        if (icon != null)
        {
            return Imaging.CreateBitmapSourceFromHIcon(
                        icon.Handle,
                        new Int32Rect(0, 0, icon.Width, icon.Height),
                        BitmapSizeOptions.FromEmptyOptions());
        }
        return null;
    }

    private void UpdateIcon(object sender, PropertyChangedEventArgs e)
    {
                RootTitleBar.Tray.Icon = RootTitleBar.Icon = Icon = GetIconImage(Paths.GetAppFile());
    }

Where RootTitleBar is declared as:

        <wpfui:TitleBar x:Name="RootTitleBar" Grid.Row="0">
            <wpfui:TitleBar.Tray>
                <wpfui:NotifyIcon>
                </wpfui:NotifyIcon>
            </wpfui:TitleBar.Tray>
        </wpfui:TitleBar>
Expected behavior

The tray icon should change when UpdateIcon is called.

Screenshots

No response

OS version

Windows 11 22H2

.NET version

.NET 6.0.401

WPF-UI NuGet version

2.0.3

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the NotifyIcon registration and Icon property update path, then reproduce the issue with the provided WPF example on Windows. Verify that changing RootTitleBar.Tray.Icon after registration updates the displayed tray icon instead of retaining the default app icon.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.