NotifyIcon.ParentHandle unused?
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 9.6k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting the NotifyIcon and InternalNotifyIconManager classes to trace how the parent window handle is selected during registration. Verify whether ParentHandle is ignored, then make the manager use the explicitly assigned handle and confirm that registration works when the main window is hidden at startup.
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