Fix "NotifyIcon" control disappear of taskbar restart
See original GitHub issueDescribe the bug The notify icon disappear of taskbar restart
To Reproduce Steps to reproduce the behavior:
- The open notify icon with application
- restart explorer.exe
Expected behavior notify icon disappear
Screenshots None
Environment (please complete the following information):
- .NET 5.0
- Visual Studio 2019
- Version 3.3.8.1
Additional context I tried to use “WM_TASKBARCREATED” message the solve issues
public sealed class TaskbarRebuildBehavior : Behavior<System.Windows.Window>
{
#region --字段--
public static readonly DependencyProperty ElementProperty = DependencyProperty.Register ("Element", typeof (UIElement), typeof (TaskbarRebuildBehavior));
private int taskbarCreated;
#endregion
#region --属性--
/// <summary>
/// 获取或设置重建的元素
/// </summary>
public UIElement Element
{
get => (UIElement)this.GetValue (ElementProperty);
set => this.SetValue (ElementProperty, value);
}
#endregion
#region --公开方法--
protected override void OnAttached ()
{
this.AssociatedObject.Loaded += (sender, e) =>
{
this.taskbarCreated = Win32_RegisterWindowMessage ("TaskbarCreated");
if (PresentationSource.FromVisual (this.AssociatedObject) is HwndSource hwndSource)
{
hwndSource.AddHook (this.WndProc);
}
};
}
#endregion
#region --私有方法--
private IntPtr WndProc (IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == this.taskbarCreated)
{
this.Element.Visibility = Visibility.Collapsed;
this.Element.Visibility = Visibility.Visible;
}
return IntPtr.Zero;
}
#endregion
#region --API--
[DllImport ("user32.dll", EntryPoint = "RegisterWindowMessage", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int Win32_RegisterWindowMessage (string lpString);
#endregion
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
NotifyIcon remains in Tray even after application closing ...
I have added notifyIcon.icon = null as well as Dispose before killing, but still icon remains taskbar until I hover mouse over it....
Read more >NotifyIcon disappeared after Windows Explorer restart #830
Sorry, it seems only occurs when explorer crashing. It can be duplicates when restart explorer.exe multi times.
Read more >My taskbar overflow is gone after latest update
Try open start and search for Command prompt or cmd as administrator and then type the following command: sfc / ...
Read more >5 Ways to Fix a Malfunctioning Windows Taskbar
2. Restart the Taskbar Services · Navigate to the File menu in the task manager. · Click on Run new task. · In...
Read more >Taskbar Disappeared/Missing Windows 10, How to Fix? (8 ...
Way 1. Check Taskbar Settings to Turn off Auto-hide · Way 2. Change the Display Resolution to an Appropriate Resolution · Way 3....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can go directly to hc:Window used.
@ghost1372 I am checking the this problem