question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix "NotifyIcon" control disappear of taskbar restart

See original GitHub issue

Describe the bug The notify icon disappear of taskbar restart

To Reproduce Steps to reproduce the behavior:

  1. The open notify icon with application
  2. 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:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Jie2GGcommented, Nov 12, 2021

so this code will work with hc:Window? or we need to create another class for hc:Window?TaskbarRebuildBehavior : Behavior<System.Windows.Window> TaskbarRebuildBehavior : Behavior<HandyControl.Controls.Window>

You can go directly to hc:Window used.

<hc:Window>
	<hc:NotifyIcon x:Name="NotifyIcon"/>
	<behaviors:Interaction.Behaviors>
		<behavior:TaskbarRebuildBehavior Element="{Binding ElementName=NotifyIcon}" />
	</behaviors:Interaction.Behaviors>
</hc:Window>
1reaction
Jie2GGcommented, Dec 27, 2021

@ghost1372 I am checking the this problem

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found