Skip to content

Commit

Permalink
fix: setting NotifyIcon.TooltipText at runtime doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
textGamex committed Jun 14, 2024
1 parent 09eeabd commit 9e2819d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Wpf.Ui.Tray/Controls/NotifyIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ private static void OnTooltipTextChanged(DependencyObject d, DependencyPropertyC
}

notifyIcon.TooltipText = e.NewValue as string ?? string.Empty;
notifyIcon.internalNotifyIconManager.TooltipText = notifyIcon.TooltipText;
_ = notifyIcon.internalNotifyIconManager.ModifyToolTip();
}

private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Expand Down
5 changes: 5 additions & 0 deletions src/Wpf.Ui.Tray/INotifyIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ internal interface INotifyIcon
/// </summary>
bool ModifyIcon();

/// <summary>
/// Tries to modify the tooltip of the <see cref="INotifyIcon"/> in the shell.
/// </summary>
bool ModifyToolTip();

/// <summary>
/// Tries to remove the <see cref="INotifyIcon"/> from the shell.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Wpf.Ui.Tray/Internal/InternalNotifyIconManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public virtual bool ModifyIcon()
return TrayManager.ModifyIcon(this);
}

/// <inheritdoc />
public virtual bool ModifyToolTip()
{
return TrayManager.ModifyToolTip(this);
}

/// <inheritdoc />
public virtual bool Unregister()
{
Expand Down
13 changes: 13 additions & 0 deletions src/Wpf.Ui.Tray/TrayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ public static bool ModifyIcon(INotifyIcon notifyIcon)
return Interop.Shell32.Shell_NotifyIcon(Interop.Shell32.NIM.MODIFY, notifyIcon.ShellIconData);
}

public static bool ModifyToolTip(INotifyIcon notifyIcon)
{
if (!notifyIcon.IsRegistered)
{
return true;
}

notifyIcon.ShellIconData.szTip = notifyIcon.TooltipText;
notifyIcon.ShellIconData.uFlags |= Interop.Shell32.NIF.TIP;

return Interop.Shell32.Shell_NotifyIcon(Interop.Shell32.NIM.MODIFY, notifyIcon.ShellIconData);
}

/// <summary>
/// Tries to remove the <see cref="INotifyIcon"/> from the shell.
/// </summary>
Expand Down

0 comments on commit 9e2819d

Please sign in to comment.