Coder Social home page Coder Social logo

h.notifyicon's Introduction

README

H.NotifyIcon

** This project is a continuation of the inactive base project to other platforms (WinUI/Uno.Skia.Wpf/Console) - ❤️ https://github.com/hardcodet/wpf-notifyicon ❤️ **

This is an implementation of a NotifyIcon (aka system tray icon or taskbar icon) for .Net 6 WPF/WinUI/Uno.Skia.WPF/Console platforms. It does not just rely on the Windows Forms NotifyIcon component, but is a purely independent control which leverages several features of the WPF/WinUI frameworks in order to display rich tooltips, popups, context menus, and balloon messages. It can be used directly in code or embedded in any XAML file.

Features

NuGet

NuGet NuGet NuGet NuGet

Install-Package H.NotifyIcon.Wpf
Install-Package H.NotifyIcon.WinUI
Install-Package H.NotifyIcon.Uno
Install-Package H.NotifyIcon.Uno.WinUI
# If you need other platforms, you can use this Core library - 
# it allows you to make NotifyIcon even in a console application.
Install-Package H.NotifyIcon

Usage

<Window
    xmlns:tb="clr-namespace:H.NotifyIcon;assembly=H.NotifyIcon.Wpf" // WPF
    xmlns:tb="using:H.NotifyIcon" // WinUI
    >
    <tb:TaskbarIcon
        ToolTipText="ToolTip"
        IconSource="/Images/TrayIcons/Logo.ico"
        ContextMenu="{StaticResource TrayMenu}"
        MenuActivation="LeftOrRightClick"
        TrayPopup="{StaticResource TrayStatusPopup}"
        PopupActivation="DoubleClick"
        TrayToolTip="{StaticResource TrayToolTip}"
        />
</Window>

Efficiency Mode image

Windows 11 introduces a new concept called Efficiency Mode.
Since, basically, this library is intended for applications to exist in the background with the ability to interact through TrayIcon, the library implements an API for this mode:

EfficiencyModeUtilities.SetEfficiencyMode(bool value)
WindowExtensions.Hide(this Window window, enableEfficiencyMode: true) // default value
WindowExtensions.Show(this Window window, disableEfficiencyMode: true) // default value
TaskbarIcon.ForceCreate(bool enablesEfficiencyMode = true) // default value

Generated icons

Example 1: image

<tb:TaskbarIcon>
    <tb:TaskbarIcon.IconSource>
        <tb:GeneratedIconSource
            Text="❤️"
            Foreground="Red"
            />
    </tb:TaskbarIcon.IconSource>
</tb:TaskbarIcon>

Example 2: image

<tb:TaskbarIcon
    IconSource="/Icons/Error.ico"
    >
    <tb:TaskbarIcon.IconSource>
        <tb:GeneratedIconSource
            Text="5"
            Foreground="Black"
            FontSize="36"
            FontWeight="Bold"
            />
    </tb:TaskbarIcon.IconSource>
</tb:TaskbarIcon>

Example 3: image

<tb:TaskbarIcon>
    <tb:TaskbarIcon.IconSource>
        <tb:GeneratedIconSource
            Text="❤️"
            Foreground="Red"
            FontFamily="Segoe UI Emoji"
            Background="AliceBlue"
            FontWeight="Bold"
            FontSize="38"
            />
    </tb:TaskbarIcon.IconSource>
</tb:TaskbarIcon>

Example 4: image

<tb:TaskbarIcon>
    <tb:TaskbarIcon.IconSource>
        <tb:GeneratedIconSource
            Text="❤️"
            BorderThickness="5"
            FontSize="46"
            >
            <tb:GeneratedIconSource.Foreground>
                <LinearGradientBrush StartPoint="0,0" EndPoint="128,128">
                    <GradientStop Color="White" />
                    <GradientStop Color="Red" />
                </LinearGradientBrush>
            </tb:GeneratedIconSource.Foreground>
            <tb:GeneratedIconSource.BorderBrush>
                <LinearGradientBrush StartPoint="0,0" EndPoint="128,128">
                    <GradientStop Color="White" />
                    <GradientStop Color="Red" />
                </LinearGradientBrush>
            </tb:GeneratedIconSource.BorderBrush>
        </tb:GeneratedIconSource>
    </tb:TaskbarIcon.IconSource>
</tb:TaskbarIcon>

Design-Time Access

It is recommended to pin the designer icon for easy viewing. To do this, go to Taskbar Settings -> Other system tray icons and enable this icon:
image

WinUI Context menu

At the moment, three modes are implemented, each with its own pros and cons.

  1. Based on your MenuFlyout, a Win32 PopupMenu will be created that will call the commands attached to your MenuFlyoutItem. This is the default. image
  2. The menu will be created in your open window, in the corner of the screen.
  3. A second transparent window will be created and used to render the native menu.. At the moment it is in the preview stage. To do this you need to explicitly set ContextMenuMode="SecondWindow"
    image

Availability of various options(depends on the version of WindowsAppSDK you are using):

Option Packaged App Unpackaged App
Transparency 🟢 from 1.1.0-preview 🟢 from 1.1.0-preview
Borderless 🔷 🟢 from 1.1.0-preview
Animations 🟢, but with borders 🟢 from 1.1.0-preview
Submenus 🔷 🔷

Behavior that needs attention

  1. This implementation currently uses the Guid associated with each TrayIcon. The default is a hash function that creates a unique Guid based on the path to your file, because Windows associates the guid with the current path when TrayIcon is registered. The only way to keep the settings when changing the file path is to use Authenticode. Read more here: https://docs.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-notifyicondataa#troubleshooting

Sample Apps

Support

Priority place for bugs: https://github.com/HavenDV/H.NotifyIcon/issues\ Priority place for ideas and general questions: https://github.com/HavenDV/H.NotifyIcon/discussions\ I also have a Discord support channel:
https://discord.gg/g8u2t9dKgE

h.notifyicon's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

h.notifyicon's Issues

[SecondWindow Mode] Context menu theme not change when App Theme change.

Describe the bug

if change app theme from app (not from system setting ), the context menu window's theme is not change.

Steps to reproduce the bug

  1. change theme from app.
  2. context menu(SecondWindow mode) theme not change.

Expected behavior

context menu window's theme should change when app theme change.

current: context menu window's theme only change when system theme change.

Screenshots

image
image

NuGet package version

2.0.56

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 11

WindowsAppSDK Version

1.1

Additional context

No response

Change IconSource to allow drawn images

I have an app that changes the icon based on dynamic data. I also let the user change background and text color and text size. I draw the image as a drawing visual and just want to use that as the IconSource using databinding.

I was able to accomplish this by changing your IconSource dependency property to a BitmapSource type and adding a ToIcon extension method for that type. I save my drawing visual as a BitmapImage and bind the IconSource to this property and it works like a charm.

System.InvalidOperationException: UpdateIcon failed can be thrown when updating GeneratedIcon Text while waking from sleep

Describe the bug

Disclaimer: Not sure if this can be considered a bug in the library or not but I've reported it just to be thorough. It's easy enough for my software to catch this exception but it would be nice if the library could handle this itself.

If you try to update the generated icon text via a timer and the PC is put to sleep for longer than the timer interval then when you wake up the PC a "System.InvalidOperationException: UpdateIcon failed" will be thrown.

Steps to reproduce the bug

  1. Create a project with a tray icon and using a DispatcherTimer to call an event handler every minute. In the event handler call something like:
    myGeneratedIcon.Text = "test";
  2. While running this code sleep the PC for 2 minutes then wake it up.

Expected behavior

The icon text should be updated instead an exception is thrown.

Screenshots

No response

NuGet package version

2.0.68

Platform

WPF

IDE

Visual Studio 2022

Windows Version

Windows 11

WindowsAppSDK Version

No response

WindowsAppSDK Type

No response

Manifest

No response

Additional context

The thrown exception:

Description: The process was terminated due to an unhandled exception. Exception Info: System.InvalidOperationException: UpdateIcon failed. at H.NotifyIcon.Core.TrayIcon.UpdateIcon(IntPtr handle) in /_/src/libs/H.NotifyIcon/Core/TrayIcon.cs:line 389 at H.NotifyIcon.TaskbarIcon.UpdateIcon(Icon value) in /_/src/libs/H.NotifyIcon.Shared/TaskbarIcon.Properties.cs:line 50 at H.NotifyIcon.GeneratedIcon.OnIconChanged(Icon oldValue, Icon newValue) in /_/src/libs/H.NotifyIcon.Shared/GeneratedIcon.cs:line 102 at H.NotifyIcon.GeneratedIcon.<>c.<.cctor>b__75_15(DependencyObject sender, DependencyPropertyChangedEventArgs args) in /_/src/libs/H.NotifyIcon.Wpf/DependencyPropertyGenerator/H.Generators.DependencyPropertyGenerator/GeneratedIcon.Properties.Icon.generated.cs:line 22 at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at H.NotifyIcon.GeneratedIcon.set_Icon(Icon value) in /_/src/libs/H.NotifyIcon.Wpf/DependencyPropertyGenerator/H.Generators.DependencyPropertyGenerator/GeneratedIcon.Properties.Icon.generated.cs:line 39 at H.NotifyIcon.GeneratedIcon.Refresh() in /_/src/libs/H.NotifyIcon.Shared/GeneratedIcon.cs:line 129 at H.NotifyIcon.GeneratedIcon.<>c.<.cctor>b__75_0(DependencyObject sender, DependencyPropertyChangedEventArgs args) in /_/src/libs/H.NotifyIcon.Wpf/DependencyPropertyGenerator/H.Generators.DependencyPropertyGenerator/GeneratedIcon.Properties.Text.generated.cs:line 22 at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at H.NotifyIcon.GeneratedIcon.set_Text(String value) in /_/src/libs/H.NotifyIcon.Wpf/DependencyPropertyGenerator/H.Generators.DependencyPropertyGenerator/GeneratedIcon.Properties.Text.generated.cs:line 38

ContextMenu shows behind of Windows taskbar

Hello,

Great job!
I found one potential issue on Win10. When I click Windows logo or the search area in Windows taskbar, to open Windows menu like this:
obraz

and then try right click my application tray icon, ContextMenu is shown but behind Windows taskbar, like this:
obraz

Not sure what is the reason. I am trying to investigate it, but without any success so far.
Adam

System.ArgumentException: Value does not fall within the expected range.

Describe the bug

When I run sample app WPF windowless it crashes with exception
OS version: 1607 OS build 14393.2608
target framework version net6-windows

other sample apps works

When running with enablesEfficiencyMode: false it looks like it works

System.ArgumentException: Value does not fall within the expected range.
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at H.NotifyIcon.Interop.InteropUtilities.EnsureNonZero(BOOL value) in C:\Users\micha\Desktop\H.NotifyIcon-master\src\libs\H.NotifyIcon\Interop\InteropUtilities.cs:line 85
   at H.NotifyIcon.EfficiencyMode.EfficiencyModeUtilities.SetProcessQualityOfServiceLevel(QualityOfServiceLevel level) in C:\Users\micha\Desktop\H.NotifyIcon-master\src\libs\H.NotifyIcon\EfficiencyMode\EfficiencyModeUtilities.cs:line 55
   at H.NotifyIcon.EfficiencyMode.EfficiencyModeUtilities.SetEfficiencyMode(Boolean value) in C:\Users\micha\Desktop\H.NotifyIcon-master\src\libs\H.NotifyIcon\EfficiencyMode\EfficiencyModeUtilities.cs:line 103
   at H.NotifyIcon.TaskbarIcon.ForceCreate(Boolean enablesEfficiencyMode) in C:\Users\micha\Desktop\H.NotifyIcon-master\src\libs\H.NotifyIcon.Shared\TaskbarIcon.cs:line 124
   at NotifyIconWpf.Sample.Windowless.App.OnStartup(StartupEventArgs e) in C:\Users\micha\Desktop\H.NotifyIcon-master\src\apps\H.NotifyIcon.Apps.Wpf.Windowless\App.xaml.cs:line 22
   at System.Windows.Application.<.ctor>b__1_0(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

### Steps to reproduce the bug

1. Use windows 10 14393.2608
2. Start sample app WPF windowless

### Expected behavior

_No response_

### Screenshots

_No response_

### NuGet package version

_No response_

### Platform

WPF

### IDE

Visual Studio 2022

### Windows Version

Windows 10

### WindowsAppSDK Version

_No response_

### WindowsAppSDK Type

Packaged

### Manifest

_No response_

### Additional context

_No response_

Exception when attempting to show window after closing it via title bar

Describe the bug

When running H.NotifyIcon.Apps.WinUI, after closing the window via the X icon in the title bar, attempting to show the window via the taskbar icon results in an exception.

Specifically, System.Runtime.InteropServices.COMException: 'The operation identifier is not valid. (0x800710DD)' when accessing window.Visible in ShowHideWindowCommand_ExecuteRequested.

Steps to reproduce the bug

  1. Run H.NotifyIcon.Apps.WinUI
  2. Close the window via the title bar X icon
  3. Left click the taskbar icon or right click and select "show/hide window"
  4. Exception occurs

Expected behavior

The window should appear.

Screenshots

image

NuGet package version

No response

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 11

WindowsAppSDK Version

1.2

WindowsAppSDK Type

Packaged

Manifest

No response

Additional context

No response

Value does not fall within the expected range.

Describe the bug

When I set the project to run in Unpackaged mode, I always get an exception and Tray has a blank icon, but in Packaged mode it's fine

Snipaste_2023-01-09_02-03-18

Value does not fall within the expected range.
Source: H.NotifyIcon.WinUI
   at H.NotifyIcon.ImageExtensions.<ToIconAsync>d__1.MoveNext()
   at H.NotifyIcon.ImageExtensions.<ToIconAsync>d__2.MoveNext()
   at H.NotifyIcon.TaskbarIcon.<OnIconSourceChanged>d__222.MoveNext()
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.<>c__DisplayClass2_0.<Post>b__0()

Snipaste_2023-01-09_02-03-53


I tried to set this in .csproj, but it didn't work

<Content Include="Assets\Icon.ico" >
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

Steps to reproduce the bug

Here is a demo created for this problem

This is the main content of the Demo:

<UserControl
   ...
   ...
    xmlns:tb="using:H.NotifyIcon"
    mc:Ignorable="d">
    <UserControl.Resources>
        <MenuFlyout x:Key="TrayContextFlyout">
            <MenuFlyoutItem Text="Exit" Click="Exit" />
        </MenuFlyout>
    </UserControl.Resources>
    <tb:TaskbarIcon 
            Width="100"
            Name="icon"
            ContextMenuMode="SecondWindow"
            ToolTipText="ViViN2N"
            ContextFlyout="{StaticResource TrayContextFlyout}"
            IconSource="ms-appx:///Assets/Icon.ico"
            >
    </tb:TaskbarIcon>
</UserControl>

Expected behavior

No response

Screenshots

No response

NuGet package version

Windows 11 22000.1335
WindowsAppSDK 1.2.221109.1
H.NotifyIcon.WinUI 2.0.75
NuGet Command Line 6.4.0.117

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 11

WindowsAppSDK Version

Other

WindowsAppSDK Type

Unpackaged

Manifest

No response

Additional context

No response

NullReferenceException on ToolTipChanged on Windows 10

Describe the bug

I'm developing on Windows 11 and test my app on Windows 10 21H2.
Everything works fine on Windows 11. However on Windows, my app crashes when I pass the mouse on the icon in the system tray.

Message:

Object reference not set to an instance of an object.

Call stack:

   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at H.NotifyIcon.TaskbarIcon.OnToolTipChange(Object sender, Boolean visible)
   at H.NotifyIcon.Core.MessageWindow.ProcessWindowMessage(UInt32 msg, WPARAM wParam, LPARAM lParam)
   at H.NotifyIcon.Core.MessageWindow.OnWindowMessageReceived(HWND hWnd, UInt32 msg, WPARAM wParam, LPARAM lParam)

Steps to reproduce the bug

  1. Be on Windows 10 build 19044.2075 (21H2) (does not reproduce on Windows 11)
  2. Using H.NotifyIcon.WinUI 2.0.68` and above.
  3. Create a windowless WinUI 3 app using this sample: https://github.com/HavenDV/H.NotifyIcon/tree/master/src/apps/H.NotifyIcon.Apps.WinUI.Windowless
  4. Update WinAppSDK to 1.2.220930.4-preview2 (I admit I didn't try with an older version)
  5. Have a XAML similar to
<tb:TaskbarIcon
        x:Key="NotifyIcon"
        Visibility="Visible"
        ToolTipText="MyTooltip"
        ContextMenuMode="SecondWindow">
        [...]
    </tb:TaskbarIcon>
  1. Start the app from Visual Studio 2022
  2. Pass the mouse above the icon in the systray, without clicking.
    image
  3. NRE exception gets raised and don't seem to be handled.
  4. App end up crashing :)

Expected behavior

No crash :) Tooltip should appear.

Screenshots

No response

NuGet package version

2.0.68
Also tried with 2.0.73

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 10

WindowsAppSDK Version

Other

WindowsAppSDK Type

Packaged

Manifest

No response

Additional context

Windows 10 build 19044.2075 (21H2)

Error in Release Mode

Describe the bug

I test Version 2.0.39 in Windows 10 and 11. I found that function works fine in Debug Mode. But crashed in Release Mode.

Steps to reproduce the bug

No response

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Platform

No response

IDE

No response

Additional context

No response

TrayToolTip doesn't work on Windows 11

Describe the bug

Using TrayToolTip to create a rich tooltip works on Windows 10 but on Windows 11 the XAML is ignored, instead hovering over the tray icon shows a tooltip that says "ToolTip".

Steps to reproduce the bug

Add a tb:TaskbarIcon.TrayToolTip to your tb:TaskbarIcon, e.g.:

<tb:TaskbarIcon.TrayToolTip>
    <ToolTip>
        <StackPanel>
            <Label Content="Header"
                   FontWeight="Bold" />
            <TextBlock Text="Body"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center" />
        </StackPanel>
    </ToolTip>
</tb:TaskbarIcon.TrayToolTip>

Expected behavior

A rich tooltip should appear (and does on Windows 10 but not Windows 11). Using the example above a tooltip should appear with a bolded line saying Header followed by a regular line saying Body.

Screenshots

Bug

NuGet package version

2.0.68

Platform

No response

IDE

Visual Studio 2022

Windows Version

Windows 11

WindowsAppSDK Version

No response

WindowsAppSDK Type

No response

Manifest

No response

Additional context

tb:TaskbarIcon.TooltipText works correctly in Windows 11.

WinUI Popups

What would you like to be added:

enigmatrix — Today at 9:12 AM
Hi, for H.NotifyIcon package for WinUI, I can't seem to make the TrayPopup work
basing off the example in H.NotifyIcon.Apps.WinUI.Windowless
enigmatrix — Today at 9:13 AM
when the Popup is to be shown, the program kills itself with COMException: Catastrophic failure

Why is this needed:

For which Platform:

  • All
  • WPF
  • WinUI
  • Uno
  • Core

Anything else we need to know?

This version seems to have many unknown problems

Describe the bug

For example, sometimes the icon is not displayed, or the process does not exist in the task manager, but the notification icon still exists and can be clicked

Steps to reproduce the bug

No response

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Platform

No response

IDE

No response

Additional context

No response

IconSource binding

Is there any way to do an IconSource binding, or to change the IconSource in a Trigger? (It doesn't appear to work)

Multiple Icons not working

Describe the bug

On Windows 11 and net v6 I am unable to produce more than one icon in both console and Wpf apps.
On setting an Icon for the second TaskBarIcon the first disappears.

This can be reproduced on the console version of the downloadable expample project.

Steps to reproduce the bug

No response

Expected behavior

Mulitple icons as in v1.xx of the library.

Screenshots

No response

NuGet package version

2.0.59
With the Console app below start it up and the type "create-second"
TestTrayIcon.zip

Platform

WPF, Console

IDE

No response

Windows Version

Windows 11

WindowsAppSDK Version

No response

Additional context

No response

Generated icons

What would you like to be added:

Generated icons with ability to set-up background/font/size/offsets/colors/borders/cornerradius

Why is this needed:

Allows you to create dynamic icons based on data. Simplifies the process of creating icons for simple applications

For which Platform:

  • All
  • WPF
  • WinUI
  • Uno
  • Core

Anything else we need to know?

Tooltip not showing (console app)

Describe the bug

Maybe I missed something but I created a simple TrayIcon with a tooltip+icon
Icon is showing correctly but no tooltip appears when moving the mouse over the icon.

Steps to reproduce the bug

trayIcon = new TrayIcon("H.NotifyIcon.Apps.Console.TrayIcon")
            {
                Icon = icon.Handle,
                ToolTip = "ToolTip Info",
                Visibility = IconVisibility.Visible
            };
trayIcon.Create();

Expected behavior

"ToolTip Info" should be displayed on mouse over

Screenshots

No response

NuGet package version

H.NotifyIcon 2.0.50

Platform

Console

IDE

Visual Studio 2022

Additional context

Using .NET 6 and console application.

[WinUI] MenuFlyout Binding and x:Bind in not supported

Describe the bug

For the default WinUI ContextMenu (PopupMenu) there is currently no way to manage this data

Steps to reproduce the bug

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Platform

WinUI

IDE

No response

Additional context

No response

VS 2022 Windows 11 Dev Environment Setup

I am using Windows 11 and VS 2022 as my dev environment. In order to get this solution going I have to do a couple of things. I thought I would post those here. I am not sure if you need to change anything or if others just need to do this if they have my issues. You will know better on that than I do.

  1. In this machine the Visual Studio Installer lists the lowest SDK you can install as 4.6.1. I had to go get 4.5.1 SDK manually.

  2. When trying to debug H.NotifyIcon.Apps.WinUI I get an error of Unable to load DLL 'Microsoft.ui.xaml.dll' or one of its dependencies. To solve this I created a launchSettings.json in the Properties folder as per this article https://docs.microsoft.com/en-us/windows/apps/windows-app-sdk/single-project-msix?tabs=csharp. I am just a hobbyist so I can only say this works for me. Hopefully, it is right.

Here are the contents of launchSettings.json :

{
  "profiles": {
    "H.NotifyIcon.Apps.WinUI (Package)": {
      "commandName": "MsixPackage"
    },
    "H.NotifyIcon.Apps.WinUI (Unpackaged)": {
      "commandName": "Project"
    }
  }
}

Tray icon disappears when activating a remote desktop session via RDP (early Dispose call)

Describe the bug

Starting an app normally and then performing a remote desktop session via RDP will cause the tray icon to disappear. The same issue can occur after closing the remote desktop session and returning to a normal desktop session. DS4Windows users seemed to have also encountered the problem when dealing with multiple monitors; I only have a single monitor so I cannot test that directly. The main problem seems to be an early call to Dispose as the RDP session will cause WPF to execute the Unloaded event followed by the Loaded event. The Unloaded call disposes the tray icon and the Loaded call will fail for EnsureNotDisposed().

Loaded += (_, _) =>
{
    try
    {
        ForceCreate(enablesEfficiencyMode: false);
    }
    catch (Exception)
    {
        Debugger.Break();
    }
};
Unloaded += (_, _) => Dispose();

https://github.com/HavenDV/H.NotifyIcon/blob/master/src/libs/H.NotifyIcon.Shared/TaskbarIcon.cs#L124

Working around the Dispose by removing the TaskbarIcon instance from the visual tree in the Window code-behind. That way the call to Unloaded (and Loaded) are avoided; need to explicitly create the TaskbarIcon instance with ForceCreate() in the code-behind now as Loaded is no longer called. Using the Application.Exit hook to dispose the TaskbarIcon instance.

Steps to reproduce the bug

  1. Start app on local session with TaskbarIcon instance created in XAML
  2. Login to machine via RDP client

Expected behavior

Tray icon to continue to be visible and usable

Screenshots

No response

NuGet package version

2.0.60

Platform

No response

IDE

No response

Windows Version

Windows 10

WindowsAppSDK Version

No response

WindowsAppSDK Type

No response

Manifest

No response

Additional context

Relevant DS4Windows issue:
Ryochan7/DS4Windows#2510

[Windows 10] ToolTipText NullReferenceException

Describe the bug

In 2.0.46 every thing works great in windows 11. But the ToolTipText will crash in Windows 10. The error message is System.NullReferenceException: 'Object reference not set to an instance of an object.'. I build on Windows 10.

Thank you. In 2.0.46 every thing works great in windows 11. But the ToolTipText will crash in Windows 10. The error message is System.NullReferenceException: 'Object reference not set to an instance of an object.'. I build on Windows 10.

Can you copy the source code of the library, point it to the project, and point to the point where this exception occurs? I've checked all the ToolTips code and don't see any options for NRE. Either I need a sample application that reproduces the error.

This is my testing code

App.xml

<Application
    x:Class="ContextSensing.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ContextSensing"
    xmlns:tb="using:H.NotifyIcon"
    >
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
            </ResourceDictionary.MergedDictionaries>

            <local:TaskbarData x:Key="TaskbarData"/>

            <tb:TaskbarIcon  x:Key="TaskbarIcon"
                             IconSource="ms-appx:///Images/logo.ico"
                             Visibility="Visible"
                             NoLeftClickDelay="True"
                             MenuActivation="RightClick"
                             ToolTipText = "Application Name"
                             >
                <tb:TaskbarIcon.ContextFlyout>
                    <MenuFlyout>
                        <MenuFlyoutItem Text="Open"
                                        />
                        <MenuFlyoutSeparator />
                        <MenuFlyoutItem Text="Exit"
                                        />
                    </MenuFlyout>
                </tb:TaskbarIcon.ContextFlyout>
            </tb:TaskbarIcon>
        </ResourceDictionary>
    </Application.Resources>
</Application>

App.xml.cs

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.UI.Xaml.Shapes;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using H.NotifyIcon;

namespace Test
{
    public partial class App : Application
    {
        public static TaskbarIcon TaskbarIcon { get; set; }
        public App()
        {
            this.InitializeComponent();
        }

        protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
        {
            m_window = new MainWindow();
            m_window.Activate();

            TaskbarIcon = (TaskbarIcon)Resources["TaskbarIcon"];
            TaskbarIcon.ForceCreate();
        }
        private Window m_window;
    }
}

If I comment out ToolTipText = "Application Name" in App.xml, everything works great.

Steps to reproduce the bug

No response

Expected behavior

No response

Screenshots

No response

NuGet package version

2.0.46

Platform

WinUI

IDE

No response

Additional context

Windows 10

System.NullReferenceException HResult=0x80004003

Describe the bug

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=WinRT.Runtime
StackTrace:
在 WinRT.ExceptionHelpers.g__Throw|20_0(Int32 hr)
在 H.NotifyIcon.TaskbarIcon.OnToolTipChange(Object sender, Boolean visible) 在 //src/libs/H.NotifyIcon.Shared/TaskbarIcon.ToolTips.cs 中: 第 231 行
在 H.NotifyIcon.Core.MessageWindow.ProcessWindowMessage(UInt32 msg, WPARAM wParam, LPARAM lParam) 在 /
/src/libs/H.NotifyIcon/Core/MessageWindow.cs 中: 第 280 行
在 H.NotifyIcon.Core.MessageWindow.OnWindowMessageReceived(HWND hWnd, UInt32 msg, WPARAM wParam, LPARAM lParam) 在 /_/src/libs/H.NotifyIcon/Core/MessageWindow.cs 中: 第 187 行

Steps to reproduce the bug

Hover over the icon

Expected behavior

No response

Screenshots

image

NuGet package version

2.0.64

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 10

WindowsAppSDK Version

1.1

WindowsAppSDK Type

No response

Manifest

No response

Additional context

No response

WinUI 3 Unpackaged app crashed when open the context menu

Describe the bug

My WinUI 3 Unpackaged app crashed when i right clicked on the tray icon.

I did not add a icon file, but i think it doesn't matter, because the sample works perfectly after i delete its icon file and related statements in xaml code.

There wasn't any exception message shown after the crash. The only message i got is the exit code : 3221226107 (0xc000027b).

Steps to reproduce the bug

  1. Install the NuGet package.
  2. Add these codes:
    In MainWindow.xaml
<Window xmlns:controls="using:AutoDL.Controls">
    <Grid>
        <!--Other Codes-->
        <controls:TrayIconContextMenu/>
    </Grid>
</Window>

In TrayIconContextMenu.xaml

<UserControl
    x:Class="AutoDL.Controls.TrayIconContextMenu"
    xmlns:tb="using:H.NotifyIcon">

    <UserControl.Resources>
        <XamlUICommand
            x:Key="ShowHideWindowCommand"
            ExecuteRequested="ShowHideWindowCommand_ExecuteRequested"
            Label="Show/Hide Window"
            Description="Show/Hide Window">
            <XamlUICommand.IconSource>
                <SymbolIconSource Symbol="OpenPane"/>
            </XamlUICommand.IconSource>
            <XamlUICommand.KeyboardAccelerators>
                <KeyboardAccelerator
                    Key="S"
                    Modifiers="Control"
                />
            </XamlUICommand.KeyboardAccelerators>
        </XamlUICommand>
        <XamlUICommand
            x:Key="ExitApplicationCommand"
            ExecuteRequested="ExitApplicationCommand_ExecuteRequested"
            Label="Exit"
            Description="Exit">
            <XamlUICommand.IconSource>
                <SymbolIconSource Symbol="ClosePane" />
            </XamlUICommand.IconSource>
            <XamlUICommand.KeyboardAccelerators>
                <KeyboardAccelerator
                    Key="E"
                    Modifiers="Control"
                />
            </XamlUICommand.KeyboardAccelerators>
        </XamlUICommand>
        <MenuFlyout
            x:Key="TrayContextFlyout"
            AreOpenCloseAnimationsEnabled="False">
            <MenuFlyoutItem Command="{StaticResource ShowHideWindowCommand}" />
            <MenuFlyoutSeparator />
            <MenuFlyoutItem Command="{StaticResource ExitApplicationCommand}" />
        </MenuFlyout>
    </UserControl.Resources>

    <tb:TaskbarIcon
        x:Name="TrayIcon"
        ToolTipText="AutoDL"
        ContextFlyout="{StaticResource TrayContextFlyout}"
        NoLeftClickDelay="True"
        ContextMenuMode="SecondWindow"
        LeftClickCommand="{StaticResource ShowHideWindowCommand}"
    />
</UserControl>

In TrayIconContextMenu.cs

public sealed partial class TrayIconContextMenu : UserControl
    {
        public TrayIconContextMenu()
        {
            this.InitializeComponent();
        }

        public void ShowHideWindowCommand_ExecuteRequested(object? _, ExecuteRequestedEventArgs args)
        {
            var window = UIHelper.MainWindow;
            if (window == null)
            {
                return;
            }

            if (window.Visible)
            {
                window.Hide();
            }
            else
            {
                window.Show();
            }
        }

        public void ExitApplicationCommand_ExecuteRequested(object? _, ExecuteRequestedEventArgs args)
        {
            TrayIcon.Dispose();
            UIHelper.MainWindow.Close();
        }
    }
  1. Run the app.
  2. Right click on the tray icon.

Expected behavior

It should show a fluent design context menu after i right clicked it.

Screenshots

No response

NuGet package version

2.0.64

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 11

WindowsAppSDK Version

1.1

WindowsAppSDK Type

Unpackaged

Manifest

No response

Additional context

No response

GeneratedIconText not found

Describe the bug

Hi, I am using the WinUI version and I am SUPER new to Windows Desktop App development.

It says "GeneratedIconText was not found in type TaskbarIcon"
Is that feature not supported on your WinUI version?

Thanks for helping!

Steps to reproduce the bug

Install latest WinUI package

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 11

WindowsAppSDK Version

1.0

WindowsAppSDK Type

Packaged

Manifest

Default

Additional context

No response

Notify icon disappear when explorer.exe restart

Describe the bug

Notify icon disappear when explorer.exe restart

Steps to reproduce the bug

No response

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Platform

No response

IDE

No response

Additional context

No response

[Question] Custom TrayIcon Id when using TaskbarIcon

The source code for TaskbarIcon.Properties.cs seems to imply that the Id dependency property can be used to edit the Id that is used by the stored TrayIcon instance. However, the OnIdChanged method does not update the Id property of the TrayIcon instance but only the Id value stored in TaskbarIcon. The TaskbarIcon Id seems to usually be an empty Guid anyway. I was wondering what the intended purpose of that dependency property is supposed to be and if the current behavior should change.

[DependencyProperty<Guid>("Id",
    Description = "Gets or sets the TrayIcon Id. Use this for second TrayIcon in same app.", Category = CategoryName)]

https://github.com/HavenDV/H.NotifyIcon/blob/master/src/libs/H.NotifyIcon.Shared/TaskbarIcon.Properties.cs#L3

I am running into an edge case where it might be useful to be able to explicitly set the Guid Id used by the stored TrayIcon instance before the TrayIcon.Create method is called. Currently using H.NotifyIcon in the app DS4Windows. When using DS4Windows normally, everything works fine. However, there is an edge case in the app where DS4Windows copies the DS4Windows.exe executable to a different file location with a different name (Custom Exe Name setting) to get around DS4 emulation blocks put in place by the Steam Input API; the Steam client will implicitly disable DS4 input controller support if the client detects either DS4Windows.exe or InputMapper.exe running on a system. Running DS4Windows with a different executable filename works around the block and the original assembly DLL DS4Windows.dll will be loaded by the executable.

Using the hashed assembly location for the generated Guid makes the TrayIcon.Create method fail in that case. Being able to set an explicit Guid seems to work around the problem and allow the weird DS4Windows workaround to function as intended.

Running Windows 10 Pro 19044.1826
.NET 6.0.7

Reference issue:
Ryochan7/DS4Windows#2484

Context menu wrong height

Describe the bug

The height of the context menu is not calculated correctly in SecondWindow mode, tried with multi language and font family/size, and it shows a scorll bar.
Sometimes it won't shown, just a little white empty box.

Steps to reproduce the bug

var settingMenuItem = new MenuFlyoutItem()
{
    Icon = new SymbolIcon(Symbol.Setting),
    Text = I18N["TrayIcon.Main"],
    // ToolTip = I18N["TrayIcon.Main.Tooltip"]
};
var exitMenuItem = new MenuFlyoutItem()
{
    Icon = new SymbolIcon(Symbol.Cancel),
    Text = I18NSource.Instance["TrayIcon.Exit"],
    // ToolTip = I18N["TrayIcon.Exit.Tooltip"]
};

var contextMenu = new MenuFlyout();
contextMenu.Items.Add(settingMenuItem);
contextMenu.Items.Add(exitMenuItem);

_taskbarIcon = new();
_taskbarIcon.ContextFlyout = contextMenu;
_taskbarIcon.IconSource = iconBitmap;
_taskbarIcon.ContextMenuMode = ContextMenuMode.SecondWindow;

if (!_taskbarIcon.IsCreated)
{
    _taskbarIcon.ForceCreate();
}

Expected behavior

Menu height is correct and do not show the scroll bar

Screenshots

image
en
ch
en2

NuGet package version

H.NotifyIcon.WinUI 2.0.50

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 10

Additional context

net6.0-windows10.0.22000.0

Throw "TryCreate Failed" exception message

Describe the bug

No response

Steps to reproduce the bug

No response

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Platform

No response

IDE

No response

Additional context

No response

ImageSource from GeneratedIcon

What would you like to be added:

Support for using GeneratedIcon in other places like Window.Icon, or more notably, MenuItem.Icon by making it an ImageSource or similar.

Why is this needed:

Easy icons without any additional dependencies like we already have for the fantastic TaskbarIcon.

Proof of concept:

<MenuItem Header="Add Item">
	<MenuItem.Icon>
		<tb:GeneratedIcon Text="+" />
	</MenuItem.Icon>
</MenuItem>

image

For which Platform:

  • All
  • WPF
  • WinUI
  • Uno
  • Core

Anything else we need to know?

Screen Scale changing

Describe the bug

When migrating from Laptop resolution (2140p display), to a 1080p display, the context menu of the notification icon area will appear in a scaled/wrong location on the display relative to the initial display resolution.

E.g, goes from being bottom right above taskbar on 2140p, to centre of the screen on the 1080p instead of rendering on the taskbar above the icon.

Steps to reproduce the bug

Run an instance of an application with h.notifyicon, context menu enabled.
on a high res laptop, right click notification area and confirm context location.
dock laptop to a lower res display
right click notification area and the context menu will appear in a different location than expected behaviour

Expected behavior

Context menu for notification area should appear above the notification icon.

Screenshots

No response

NuGet package version

2.0.59

Platform

WPF

IDE

Visual Studio 2022

Windows Version

Windows 11

WindowsAppSDK Version

1.1

Additional context

No response

Visibility binding is not working

Describe the bug

Steps to reproduce the bug

After first Hide() it does not show icon.

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Platform

All

IDE

No response

Additional context

No response

UWP Support

What would you like to be added:

Why is this needed:

For which Platform:

  • All
  • WPF
  • WinUI
  • Uno
  • Core

Anything else we need to know?

ContextMenuMode="SecondWindow" can perform strangely for WinUI 3

Describe the bug

I really appreciate the idea of the new context menu option. Yet I found in my own project that its window size and the menu item height could be strange, and could be even different for the 1st time and the later time shown the menu. So I validated with your sample app and reproduced the issue.

As you can see in the screenshots, the context menu item shown the 2nd time is higher than the one shown the 1st time. Both screenshots indicate that the context menu window has incorrect size.

I notice that the screenshot in the README can demonstrate a perfect context menu. So this really confuses me.

Steps to reproduce the bug

  1. Build the project with Visual Studio 2022.
  2. Run the packaged H.NotifyIcon.Apps.WinUI app.
  3. Right click the app icon in the taskbar corner to show the context menu (1st time).
  4. Dismiss the context menu and repeat Step 3 (2nd time).

Expected behavior

Show as the screenshot in README.

Screenshots

1
2

NuGet package version

No response

Platform

WinUI

IDE

Visual Studio 2022

Additional context

Windows 11 Pro 22000.652

GeneratedIconText Scale of Text

What would you like to be added:

I would like to have the generated icon display the full text that it gets supplied and not only one to two chars.

Why is this needed:

I want to display wattage numbers (very similar to HWInfos Tray Texts)

For which Platform:

  • All
  • WPF
  • WinUI
  • Uno
  • Core

Anything else we need to know?

Thanks for the awesome package :)

WinUI3 Flyout Question

For me when I try the test WinUI3 app it shows the context flyout for the taskbar icon in the bottom corner of the application window.

Is this intended? If it is, then is there a way to have it show a context menu over the icon in the system tray?

NullReferenceException when hover at tray icon in WinUI3

Describe the bug

When I run the app and hover over the system tray icon, it crashes with a NullReferenceException.

System.NullReferenceException
  HResult=0x80004003
  Message = Object reference not set to an instance of an object.
  Source = WinRT.Runtime
  TraceStack:
   в WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   в H.NotifyIcon.TaskbarIcon.OnToolTipChange(Object sender, Boolean visible)
   в H.NotifyIcon.Core.MessageWindow.ProcessWindowMessage(UInt32 msg, WPARAM wParam, LPARAM lParam)
   в H.NotifyIcon.Core.MessageWindow.OnWindowMessageReceived(HWND hWnd, UInt32 msg, WPARAM wParam, LPARAM lParam)

Steps to reproduce the bug

  1. Create WinUI3 application
  2. Add H.NotifyIcon packages
  3. Add to my window grid tb:TaskbarIcon with ToolTipText
  4. Run app and hover over the system tray icon of app

Expected behavior

No response

Screenshots

No response

NuGet package version

2.0.59

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 10

WindowsAppSDK Version

1.1

Additional context

If ToolTipText is empty there is no error

ShowNotification() with custom icon throws exception

Describe the bug

ShowNotification() with custom icon throws exception
It doesn't show up in the console app

Steps to reproduce the bug

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Platform

WPF

IDE

No response

Additional context

No response

ToolTipText doesn't work from 2.0.25

Describe the bug

The tray icon shows the tooltip text properly in 2.0.24, but no tooltip is shown from 2.0.25.

Steps to reproduce the bug

<tb:TaskbarIcon
    LeftClickCommand="{x:Bind CommandsViewModel.ToggleMainWindowVisibilityCommand}"
    IconSource="ms-appx:///Assets/AppIcon/AppIcon.ico"
    MenuActivation="RightClick"
    NoLeftClickDelay="True"
    ToolTipText="Test">
    <tb:TaskbarIcon.ContextFlyout>
        <MenuFlyout>
            <MenuFlyoutItem
                Text="Settings" />
            <MenuFlyoutSeparator />
            <MenuFlyoutItem
                Text="Exit" />
        </MenuFlyout>
    </tb:TaskbarIcon.ContextFlyout>
</tb:TaskbarIcon>

Expected behavior

The tray icon's tooltip text should be shown as previous in 2.0.24.

Screenshots

No response

NuGet package version

= 2.0.25

Platform

WinUI

IDE

Visual Studio 2022

Additional context

WinUI 3 from Windows App SDK 1.0

Unpackaged WinUI apps crash when using ms-appx URIs

Describe the bug

Unpackaged WinUI applications crash when providing an ms-appx URI to IconSource. This is likely because the StorageFile API used for loading images requires package identity1.

var file = await StorageFile.GetFileFromApplicationUriAsync(uri);
using var stream = await file.OpenStreamForReadAsync().ConfigureAwait(true);

Steps to reproduce the bug

  1. Check out the current H.NotifyIcon master branch (1d3326c).
  2. Change
    <tb:TaskbarIcon
    x:Key="TrayIcon"
    Visibility="Visible"
    GeneratedIconText="❤️"
    GeneratedIconForeground="Red"
    ToolTipText="ToolTip"
    ContextMenuMode="SecondWindow"
    LeftClickCommand="{StaticResource ShowHideWindowCommand}"
    NoLeftClickDelay="True"
    >
    to use IconSource="ms-appx:///Assets/Red.ico".
  3. Start debugging H.NotifyIcon.Apps.WinUI.Windowless as an unpackaged app.

Expected behavior

The icon specified by IconSource is displayed in the system tray.

Screenshots

No response

NuGet package version

Current master of H.NotifyIcon (1d3326c).

Platform

WinUI

IDE

Visual Studio 2022

Additional context

No response

Footnotes

  1. https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-supported-api#apis-that-require-package-identity

Replace System.Drawing to SkiaSharp/Microsoft.Maui.Graphics

Fix nuget repository

Describe the bug

There are new versions available for H.NotifyIcon.* but referenced dependency H.NoticyIcon has not been updated accordingly. This results in nuget installation / update failure.

Steps to reproduce the bug

Try to update e.g. H.NotifyIcon.Wpf nuget to version 2.*

Expected behavior

No response

Screenshots

obraz

NuGet package version

No response

Platform

All

IDE

Visual Studio 2022

Additional context

No response

Strange menu position and width

Describe the bug

The menu would appear at the top of the screen on first right-click

More right-clicks would take it to the right position, but the width of it is still strange unless manually set it


And it seems that the menu has a poor performance (a little bit lag, low animation fps, relatively high cpu usage)

Steps to reproduce the bug

No response

Expected behavior

No response

Screenshots

The menu would appear at the top of the screen on first right-click
图片


More right-clicks would take it to the right position, but the width of it is still strange unless manually set it
图片


图片

NuGet package version

H.NotifyIcon.Wpf 2.0.59

Platform

WPF

IDE

Visual Studio 2022

Windows Version

Windows 11

WindowsAppSDK Version

No response

Additional context

Code for H.NotifyIcon

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:tb="http://www.hardcodet.net/taskbar"
    xmlns:vm="clr-namespace:Leanode.ViewModels">
    <tb:TaskbarIcon
        x:Key="NotifyIcon"
        IconSource="/Resources/Logo.ico"
        LeftClickCommand="{Binding ShowWindowCommand}"
        NoLeftClickDelay="True"
        ToolTipText="Left-click to show window, right-click for menu">
        <tb:TaskbarIcon.DataContext>
            <vm:NotifyIconViewModel />
        </tb:TaskbarIcon.DataContext>
        <tb:TaskbarIcon.ContextMenu>
            <ContextMenu ItemsSource="{Binding MenuItems}">
                <ContextMenu.ItemTemplate>
                    <DataTemplate DataType="MenuItem">
                        <MenuItem Command="{Binding Command}" Header="{Binding Text}" />
                    </DataTemplate>
                </ContextMenu.ItemTemplate>
            </ContextMenu>
        </tb:TaskbarIcon.ContextMenu>
    </tb:TaskbarIcon>
</ResourceDictionary>
using System.Windows;
using H.NotifyIcon;

namespace Leanode
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private TaskbarIcon? _notifyIcon;

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            
            _notifyIcon = (TaskbarIcon)TryFindResource("NotifyIcon");   
            _notifyIcon.ForceCreate();
        }

        protected override void OnExit(ExitEventArgs e)
        {
            _notifyIcon?.Dispose();
            base.OnExit(e);
        }
    }
}

Meanwhile, I'm using MaterialDesignThemes.

Creating a TaskbarIcon in-code causes windows to treat each instance as unique

Describe the bug

I may be doing something incorrectly, if so feel free to correct me.

I'm creating a new TaskbarIcon in-code by using

taskbarIcon = new TaskbarIcon();
taskbarIcon.Icon = new System.Drawing.Icon("Assets/(The icon)");
taskbarIcon.ToolTipText = "(tooltip name)";

But this creates a new "unique" icon every time, which floods settings and doesn't let the user choose if the icon should be in the overflow menu or not.

Steps to reproduce the bug

  1. Create a TaskbarIcon manually, using the code described above
  2. Launch the app multiple times
  3. Check "Other system tray icons" in settings

Expected behavior

Only one entry for the application

Screenshots

image

NuGet package version

2.0.24

Platform

WinUI

IDE

Visual Studio 2022

Additional context

I may be doing something wrong, or creating a TaskbarIcon in-code may be fully unsupported.

It is quite possible there's simply some ID property or something I'm not aware I need to set.

[WPF] Context menu incorrect position on system with multiple displays

Describe the bug

I have 2 displays and the secondary display is located on top of primary. If I move main taskbar (taskbar with tray icons) to the secondary display context menu opens on bottom of primary display.

Steps to reproduce the bug

No response

Expected behavior

No response

Screenshots

No response

NuGet package version

2.0.74

Platform

WPF

IDE

Visual Studio 2022

Windows Version

Windows 10

WindowsAppSDK Version

No response

WindowsAppSDK Type

None

Manifest

No response

Additional context

No response

Pinned TrayIcons are not displayed until another TrayIcon appears

Describe the bug

For some reason Windows 11 doesn't actually realize a new icon has been added (when an icon is set to not go to the overflow tray) until you open another icon (like task manager, which makes both of them show up) but I don't think that is related to this library.
This may also be a Windows 11 bug which Microsoft needs to fix.

Steps to reproduce the bug

I still don't think this is your problem, but here's what happens once you open task manager (or any other application that adds an icon)

screen.mp4

This does not happen in the overflow up arrow tray thing, in which case it works fine. I do not know if this is a change in the latest version, as due to the changing guids, all icons would go to the overflow tray.

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Platform

All

IDE

No response

Additional context

Windows 11 22H2 (OS Build 22593.1) (Current insiders beta)
Based on conversation in #13

Separate WPF parts

Nice work!

Have you considered splitting this library into two parts: One for creating icons regardless of UI framework, with just generic classes, and an extension that adds the WPF piece.

The reason for that is reusing the trayicon creation in other UI frameworks, like services, WinUI3 etc. I was able to reuse your interop code and re-write the trayicon class a bit to just create the icon, without using any WPF types, and have it work with WinUI3.
But if you just had the core classes in its own package, I could create a WinUI extension that's equivalent to the WPF bits, but reusing all the awesome interop work you've done.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.