Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotifyIcon.ParentHandle unused? #1256

Open
fubar-coder opened this issue Oct 20, 2024 · 0 comments
Open

NotifyIcon.ParentHandle unused? #1256

fubar-coder opened this issue Oct 20, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@fubar-coder
Copy link

Describe the bug

I wanted to set the parent handle directly instead of using the automatic mechanism which tries to get the HwndSource from the main window, which might not be available yet due to the window being hidden at startup.

It seems that the property ParentHandle isn't used at all, neither by the NotifyIcon class nor the InternalNotifyIconManager.

To Reproduce

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);

    var mainWindow = new MainWindow();
    MainWindow = mainWindow;

    var helper = new WindowInteropHelper(mainWindow);

    var trayIcon = new NotifyIcon()
    {
        Icon = new BitmapImage(new Uri("pack://application:,,,/Resources/icon.ico")),
        ContextMenu = new ContextMenu()
        {
            Items =
            {
                new MenuItem()
                {
                    Header = "Exit",
                }
            }
        },
        ParentHandle = helper.EnsureHandle(),
        TooltipText = "Test",
    };

    trayIcon.Register();
    _trayIcon = trayIcon;
}

Expected behavior

The InternalNotifyIconManager should use the ParentHandle instead of trying to find the handle of the main window.

Screenshots

No response

OS version

Win 11 24H2

.NET version

.NET Framework 4.7.2

WPF-UI NuGet version

4.0.0-rc.2

Additional context

No response

@fubar-coder fubar-coder added the bug Something isn't working label Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant