Giter Site home page Giter Site logo

wpf-notifyicon's Introduction

Hardcodet NotifyIcon for WPF

๐Ÿš€ This is the new official repository of the Hardcodet WPF NotifyIcon ๐Ÿš€

Current version: Nuget

Description

This is an implementation of a NotifyIcon (aka system tray icon or taskbar icon) for the WPF platform. It does not just rely on the Windows Forms NotifyIcon component, but is a purely independent control which leverages several features of the WPF framework 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 at a glance

  • Custom Popups (interactive controls) on mouse clicks.
  • Customized ToolTips (Vista and above) with fallback mechanism for xp/2003.
  • Rich event model including attached events to trigger animations in Popups, ToolTips, and balloon messages. I just love that.
  • Full support for standard Windows balloons, including custom icons.
  • Custom balloons that pop up in the tray area. Go wild with styles and animations ๐Ÿ™‚
  • Support for WPF context menus.
  • You can define whether to show Popups on left-, right-, double-clicks etc. The same goes for context menus.
  • Simple data binding for Popups, ToolTips and custom balloons through attached properties and derived data context.
  • Command support for single / double clicks on the tray icon.

Tutorial and Support

A comprehensive tutorial that complements the attached sample application can be found on the Code Project: http://www.codeproject.com/KB/WPF/wpf_notifyicon.aspx

XAML Declaration Sample

The sample below shows some of the properties of the control. For a more comprehensive sample, have a look at the sample application that comes with the download.

<Window
  x:Class="Hardcodet.NetDrives.UI.SystemTray.Sample"
  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">

    <tb:TaskbarIcon x:Name="myNotifyIcon"
                    Visibility="Visible"
                    ToolTipText="Fallback ToolTip for Windows xp"
                    IconSource="/Images/TrayIcons/Logo.ico"
                    ContextMenu="{StaticResource TrayMenu}"
                    MenuActivation="LeftOrRightClick"
                    TrayPopup="{StaticResoure TrayStatusPopup}"
                    PopupActivation="DoubleClick"
                    TrayToolTip="{StaticResource TrayToolTip}"
      />

</Window>

Contributors and Thanks

Hi, I'm Philipp! This little library was originally written by me, but is currently mostly maintained by Jan Karger and Robin Krom. Big, big kudos to the two of you, and everybody else who contributed to this library. You rock!

Make sure to check out Robin's great Greenshot tool (that I use on a daily basis), and Jan's MahApps UI framework.

wpf-notifyicon's People

Contributors

alivedevil avatar archi-doc avatar devpelux avatar hardcodet avatar hemnstill avatar lakritzator avatar maksymslota avatar paulcscharf avatar punker76 avatar teadrivendev avatar

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

wpf-notifyicon's Issues

Launching Window from NotifyIcon using Windowless sample

Hi,
I have just recently started using this library and everything works as it should while having a debugger attached
However as soon as I do not have the debugger attached my main window refuses to show.
Using exactly the same code and I am not sure what is wrong.

I can provide a code sample if you like

Standard (OS) Balloon Tips not Showing

When I get a copy of the source and build NotifyIconWpf.Sample.ShowCases the standard OS balloon tips don't show:

grafik

It doesn't matter whether I choose "Show as Info", "Show as Error" or "Show Custom Icon".

The custom balloon shows. Everything else also seems to work as expected.
grafik

I'm on Windows 10 Version 2004 (1904.1165).

I also checked the OS settings which AFAIK seem to be ok:

grafik

Focus assist is turned off:
grafik

The sample app also doesn not show up in the list of notification senders:
grafik

(Not sure if applications which show balloon tips are supposed to show up in this list).

Administrate templates are all on "Not configured":
grafik

(same goes for "Computer Configuration")

Localization

Dear Hardcodet Team,

First I want to say thanks for you amazing work, you really did great job, especially supporting .net core.

I have small project targeting .Net 5, where I took advantage of Microsoft.Extensions.Localization to implement localization.
On the one hand, in some places I use IStringLocalizer directly from the code. On the other hand, I have implemented markup extension, that also relies on IStringLocalizer, and I am using that markup extension in XAML, also for WPF Notify Icon.

The problem is that, when I change the language in the app, WPF Notify Icon stays on the previous language configuration.
Is there some method that will be called before context many of WPF Notify Icon appears, that I can override where I can set the CurrentUICulture on that thread according to configuration, so that the context menu (through above mentioned markup extension) can be localized without restarting the whole app?

Thank you and best regards,
Nole

Add keyboard handling

With Windows 7 new events were introduced to the shell notify icon, as documented here.

Short form: before mouse events were created, even when no mouse was used, now there are special events for this.

This was found while improving the readability in #10 and we decided to make an issue for the keyboard event handling on it's own to prevent mixing stuff. All the details are in there!

Tooltips Not Shown Above Taskbar / Taskbar Popup

If you try to show the tooltip, either via ToolTipText or TrayToolTIp, the tooltip can get into a state where it does not show above the Windows Taskbar. This only occurs when the Windows Start Menu is also open at the same time. See included image.

Is there a workaround to get this to show properly? Other applications don't seem to have an issue showing their tooltips. This can be reproduced by running any of the sample applications and hovering over the icon when the start menu is open.

ToolTip Error

Can't use another icon

I'm new on WPF but I'm trying to work with the windowless project and I'm trying to use another icon and route.

What I did was to create a new folder called img in the project and then I've added an icon called green.ico
Then in NotifyIconResources.xaml I've changed IconSource="Red.ico" with IconSource="/img/green.ico".
When I run the program, I got an error IOException: Cannot locate resource 'green.ico'.
What's happening? do I need to do something else?

MenuItems in ContextMenu on Tray Icon Using Commands Always Disabled

CS

public static RoutedCommand ChooseFolderCommand = new RoutedCommand();

private void ChooseFolderCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
	// ...
}

XAML

<Window.CommandBindings>
    <CommandBinding Command="local:MainWindow.ChooseFolderCommand" Executed="ChooseFolderCommandExecuted" />
</Window.CommandBindings>

<tb:TaskbarIcon x:Name="trayMenu" IconSource="/Assets/quill-64.ico">
    <tb:TaskbarIcon.ContextMenu>
        <ContextMenu Opened="ContextMenu_Opened">
            <MenuItem Header="Choose folder" Command="local:MainWindow.ChooseFolderCommand" />
        </ContextMenu>
    </tb:TaskbarIcon.ContextMenu>
</tb:TaskbarIcon>

Noteworthy

  • The Command gets never disabled (no CanExecute), yet when debugging, the IsEnabled property of the MenuItem remains false.
  • The same Command is used in a Menu and works as expected.
  • In order to resolve the issue, I had temporarily attached a CanExecute-method to my CommandBinding, which doesn't get called ever for the tray icon's context menu. This remains the case even when calling CommandManager.InvalidateRequerySuggested() in e.g. the Opened event of the ContextMenu.
  • The above works fine when using a Click event hander instead
  • Others seem to have the same issue, see this question on StackOverflow

TrayInfo.GetDeviceCoordinates is giving wrong coordinates after system scale change

Found an issue with wpf-notifyicon 1.0.8 where TrayInfo.GetDeviceCoordinates() returns wrong coordinates. To reproduce that, set the system scale to 100%, open the app that uses wpf-notifyicon, call var ScreenLocation = Hardcodet.Wpf.TaskbarNotification.Interop.TrayInfo.GetTrayLocation();
Then change the scale to 150% and call GetTrayLocation() again, it will return the same result.

The problem is that GetTrayLocation() does some coordinates transformation depending on current system DPI:

        public static Point GetDeviceCoordinates(Point point)
        {
          return new Point
          {
              X = (int)(point.X / SystemInfo.DpiFactorX),
              Y = (int)(point.Y / SystemInfo.DpiFactorY)
          };

SystemInfo.DpiFactorX and SystemInfo.DpiFactorY are caching the old values. There needs to be some sort of system DPI change awareness, or, alternatively, do not cache the DPI Factor and do win32 API calls every time one of the properties are triggered.

Command ability to execute doesn't seem possible to refresh

I've got two entries in the tray (based on the sample):

<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:local="clr-namespace:EarlyBillingNotification">
    
    <ContextMenu x:Shared="false" x:Key="SysTrayMenu">
        <MenuItem Header="Start monitor" Command="{Binding StartMonitorCommand}"/>
        <MenuItem Header="Stop monitor" Command="{Binding StopMonitorCommand}"/>
        <Separator />
        <MenuItem Header="Exit" Command="{Binding ExitApplicationCommand}"/>
    </ContextMenu>
    <tb:TaskbarIcon x:Key="NotifyIcon"
                    Visibility="Visible"
                    ToolTipText="Billing checks"
                    IconSource="foo.ico"
                    ContextMenu="{StaticResource SysTrayMenu}"
                    MenuActivation="LeftOrRightClick">
        <tb:TaskbarIcon.DataContext>
            <local:NotifyIconModelView/>
        </tb:TaskbarIcon.DataContext>
    </tb:TaskbarIcon>
</ResourceDictionary>

In the model I set them both using the RelayCommand:

            StartMonitorCommand = new RelayCommand(StartMonitor, () => !MonitorRunning);
            StopMonitorCommand = new RelayCommand(StopMonitor, () => MonitorRunning);

Initially the Stop Monitor entry is disabled as expected. But after running the command and the value switching, I don't get feedback, even though I'm doing manual notification:

                StartMonitorCommand.NotifyCanExecuteChanged();
                StopMonitorCommand.NotifyCanExecuteChanged();

Should this just work? Am I missing something simple?

ContextMenu not showing after sleep, RDC connection or resolution change

Context menu on tray icon would be working as expected, and would stop showing after some of these events:

  • Computer going to sleep and waking up
  • Logging via Windows Remote Desktop
  • Multi-Monitor positions changed or resolution changed
    This was happening inconsistency but reported by multiple users

Culture is lost

After setting the culture to a culture other than the default culture, I can see my my resources load properly however once the notifyicon is instantiated, my non-standard culture is lost and the default applied. I searched the code and do not see anywhere the code sets the Culture so I am wondering if the underlying API within Windows is setting the culture back.

The MainView cannot trigger the mouse events when TrayPopup is activated.

.NET5.0 WPF WindowChrome

I used the custom TrayPoup as the tray right click menu.
When I right-click to activate TrayPopup, none of the buttons on the main view respond to mouse move.It looks like a new window has been opened using the "ShowDialog" function.
After clicking a button in TrayPoup, Traypopup is turned off by setting the โ€œVisibility.Collapsedโ€ property of Traypopup.After turning off TrayPoup, the main view still cannot trigger the mouse move event until you click on the form with the mouse.

I tried using Window.Focus function but it didn't work.

Am I using it the wrong way?Or if there are other solutions, could you please ask me,thank you very much!

[FR] Add "CustomBalloonClosed" event

It would be nice to have also the CustomBalloonClosed event on TaskbarIcon (similar to the TrayBalloonTipClosed) - which would be triggered after a custom balloon was closed (both explicitly by calling CloseBalloon() or implicitly by timeout).

My use case: I want to show multiple custom successive balloons (one after another), so I'm storing these balloons in a queue. But, I need to be notified when the previous balloon was closed, so I can move to the next balloon in my queue and show it.

(I'm using TaskbarIcon.CustomBalloon.Closed as a workaround, but this approach is a bit complicated because the Popup instance in the CustomBalloon property is replaced when calling the ShowCustomBalloon, so I have to register handlers to the Popup.Closed event for every new CustomBalloon)

ContextMenuOpening is not firing

WPF .NET5 Nuget Version 1.0.8, ContextMenuOpening event never fires when context menu opens. See example code below

<tb:TaskbarIcon.ContextMenu>
    <ContextMenu ContextMenuOpening="ContextMenu_ContextMenuOpening" />
</tb:TaskbarIcon.ContextMenu>

Workaround is listening to PreviewTrayContextMenuOpen on tb:TaskbarIcon.ContextMenu

Issue when the icon is in the systray popup window

In the WindowLess sample, if the icon is in the popup window that shows additional systray icons, when operating on the context menu or double-clicking the icon, the popup window does not close itself.

Cannot show icon

MyNotifyIcon.ShowBalloonTip("Tips", "Contents", new System.Drawing.Icon("icon.ico"),true);
Cannot show any built-in icon or customized icon.

Version๏ผš1.0.8 ๏ผˆlatest version from nuget๏ผ‰
.Net Framework 4.7.2
Window 10

Context menu breaks after resuming from machine Lock/Unlock or Sleep

Steps to reproduce the issue:

  1. Check several times to make sure RMB on Tray icons opens Context Menu
  2. Press Win+L to lock machine (or put computer to sleep)
  3. Unlock machine by entering password/pin
  4. Right click on Tray Icon
    Nothing happens

Same result whether the Context Menu is realized through xaml only or in code behind
VS2019 and .NET Framework 4.8

License consideration?

Hi, I love all your controls here.
However, your license, the CPOL, prevents the library from being used in many open source projects because of its restrictions on "illegal" and "immoral" usage.
Could you please re-release this package under another popular license out there, such as the LGPLv3 or the MIT license? This could help other projects a lot!
Anyway, I don't see much use of notify icons for misdeeds anyway.

Thanks.

Is there a release coming any time soon

I've looked at the various comments in discussions around this repo - .NET Core and .NET 5 support have been added and there hasn't been a release of this package in what is now over four years.

The work has been done but there isn't even a preview to test? I understand there may be trepidation in terms of breaking/backward compat, but keeping a release this long when the programming has been done is arbitrary.

If you need help - I am more than available in this regard.

When can we expect a release here?

cc @punker76 @Lakritzator

RightClickCommand missing

I have a requirement to show the application window on any interaction with the tasktray icon.
LeftClickCommand works great, but there is nothing for right-click.
I tried handling MouseRightButtonUp but it doesn't seem to work. I think the event doesn't originate from the notify icon.

        <tb:TaskbarIcon x:Name="MyNotifyIcon"
                        NoLeftClickDelay="True"                  
                        IconSource="{Binding Path=DynamicAppIcon}"                        
                        DoubleClickCommand="{Binding ShowWindowCommand}"
                        LeftClickCommand="{Binding ShowWindowCommand}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseRightButtonUp">
                    <i:InvokeCommandAction Command="{Binding ShowWindowCommand}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </tb:TaskbarIcon>

Would it be possible to create a RightClickCommand ?

Permanently visible icon

Is there a way to stop windows hiding the icon?
I know "every app" thinks its icon should be permanently visible, haha, and I don't expect that permanently visible needs to be a feature of this library, I just want to know how to at least initialize my icon to stay visible and let the user hide it they want to.
Thanks in advance :)

open Popup with mouse over the Notify Icon

Hi Philipp,

the ToolTip can be opened with mouse over the Notify Icon, but the Popup only works with a click.

How I can also open the Popup with a mouse over the icon?

Best regards

Download for WPF .NET Core 3.1

I don't know how to download the newest version for WPF .NET Core 3.1

The version on NuGet was "Last updated" on 4/2/2016.

Can the whole code be placed in just one folder? I don't want to lose my overview.

Global Hot Keys support

WPF: Implementing Global Hot Keys
https://social.technet.microsoft.com/wiki/contents/articles/30568.wpf-implementing-global-hot-keys.aspx

It would be great, if the window is in system tray, I just click a Global Hot Key e.g. ALT + L and the window appears.

Is this maybe already possible?

Any links how I can achieve this with the latest version?

"but when the form gets hidden and minimized to the system tray windows is unable to send the event message to the forms handle"

Is there still a solution?

System Tray getting Minimized

The System tray getting minimized when mouse pointer is moved to a different position.But the Context menu remains,which is not the default behavior of Windows NotifyIcon. Please fix this ASAP.

Correctly identify the BalloonTip clicked

Last few weeks I have been trying to get Windows 10 notifications working with WPF (custom deployment was causing issues with App Identity). Today decided to try NotifyIcon BalloonTip and to my surprise, It integrates with Windows 10 notification natively.

The is great news. What I would like next is to enable interaction so I know which of the BalloonTip was clicked by user. I can't see any ways to pass unique indenfier to each tip.

Has anyone tried this ?

"Win32Exception The operation completed successfully" on IconSourcePropertyChanged

I've been using NotifyIcon for a long time now for my application which was working fine on my test machines but I receive a lot of logs with the aforementioned unhandled exception and this stack trace:

System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully.
   at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
   at Hardcodet.Wpf.TaskbarNotification.Util.ToIcon(ImageSource imageSource)
   at Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.IconSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.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.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   at System.Windows.Data.MultiBindingExpression.TransferValue()
   at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
   at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
   at MS.Internal.Data.PropertyPathWorker.RefreshValue()
   at MS.Internal.Data.ClrBindingWorker.ScheduleTransferOperation(Object arg)
   at MS.Internal.Data.DataBindOperation.Invoke()
   at MS.Internal.Data.DataBindEngine.ProcessCrossThreadRequests()
   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)

The NotifyIcon has several variants of icons that might change dynamically. All variants of the icons are 32x32 .ico files.
The app is for Windows 10 18362.0+ and exceptions occur on different versions of it and at a random execution time. The app is on .net core 3.1, I've tried changing the package to .net core fork but the exception was still there.

Balloontip wont show

I have a working tray icon, with context menu and everything works fine so far. But if I try to show a balloon tip with ShowBalloonTip just nothing happens.

What might be my mistake?

The root Visual of a VisualTarget cannot have a parent.

NotifyIcon.Wpf.TaskbarNotification (.NET 4.0) v1.0.5.0

I get this exception when attempting to show a dialog window.
There are other people on StackOverflow who have encountered this error as well.
https://stackoverflow.com/q/28833702/2596334

 ExMessage   = The root Visual of a VisualTarget cannot have a parent.
 ExType      = System.ArgumentException
 StackTrace  =    at System.Windows.Media.CompositionTarget.SetRootVisual(Visual visual)  
    at System.Windows.Media.CompositionTarget.set_RootVisual(Visual value)
    at System.Windows.Interop.HwndTarget.set_RootVisual(Visual value)
    at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
    at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
    at System.Windows.Controls.Primitives.Popup.SetRootVisualToPopupRoot()
    at System.Windows.Controls.Primitives.Popup.CreateWindow(Boolean asyncCall)
    at System.Windows.Controls.Primitives.Popup.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    at System.Windows.FrameworkElement.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 System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
    at System.Windows.Controls.Primitives.Popup.CreateRootPopup(Popup popup, UIElement child)
    at System.Windows.Controls.ToolTip.HookupParentPopup()
    at System.Windows.Controls.ToolTip.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    at System.Windows.FrameworkElement.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 Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.OnToolTipChange(Boolean visible) in c:\git\OSS\notifyicon-wpf\Hardcodet.NotifyIcon.Wpf\Source\NotifyIconWpf\TaskbarIcon.cs:line 496
    at Hardcodet.Wpf.TaskbarNotification.Interop.WindowMessageSink.ProcessWindowMessage(UInt32 msg, IntPtr wParam, IntPtr lParam) in c:\git\OSS\notifyicon-wpf\Hardcodet.NotifyIcon.Wpf\Source\NotifyIconWpf\Interop\WindowMessageSink.cs:line 296
    at Hardcodet.Wpf.TaskbarNotification.Interop.WindowMessageSink.OnWindowMessageReceived(IntPtr hwnd, UInt32 messageId, IntPtr wparam, IntPtr lparam) in c:\git\OSS\notifyicon-wpf\Hardcodet.NotifyIcon.Wpf\Source\NotifyIconWpf\Interop\WindowMessageSink.cs:line 213
    at MS.Win32.UnsafeNativeMethods.ITfMessagePump.GetMessageW(MSG& msg, IntPtr hwnd, Int32 msgFilterMin, Int32 msgFilterMax, Int32& result)
    at System.Windows.Threading.Dispatcher.GetMessage(MSG& msg, IntPtr hwnd, Int32 minMessage, Int32 maxMessage)
    at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
    at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
    at System.Windows.Window.ShowHelper(Object booleanBox)
    at System.Windows.Window.Show()
    at System.Windows.Window.ShowDialog()

ToolTipText is not showing when using Binding to ToolTipText property

I have the following in my XAML:

<tb:TaskbarIcon.TrayToolTip> <Border Background="White" BorderBrush="Black" BorderThickness="2" CornerRadius="4" Opacity="0.8" Width="160" Padding="5"> <TextBlock Text="{Binding ToolTipText}" Foreground="Black" TextAlignment="Center" TextWrapping="WrapWithOverflow" /> </Border> </tb:TaskbarIcon.TrayToolTip>

I do have the ToolTipText property defined:

ToolTipText="{StaticResource ApplicationName}"

And that resource is in my App.xaml in a ResourceDictionary:

<system:String x:Key="ApplicationName">This is a test.</system:String>

This same binding is working as the Window Title, so I know it works.

What I get out of this is an empty box with no text. If I change the Binding to a text value that I have defined, it does show up, so I know it's not some strange display issue with the text.

WhatToTheHeck

When I use Visual Studio's built-in "Live Visual Tree", the DataSource on "TaskbarIcon.TrayToolTip" is the associated ViewModel for the Window. If I add a "ToolTipText" property to my ViewModel, then it shows up properly.

According to the "Implicit Binding through DataContext" section of https://www.codeproject.com/Articles/36468/WPF-NotifyIcon-2, it should be binding to the TaskbarIcon, not the ViewModel of the containing window.

I don't know if this is a WPF bug, or something else. My project is targetting .Net Core 3.1, if that matters. I am referencing v1.0.10 of your NotifyIcon.

Icons won't show when not using pack URIs

When using the C# API to create a new tray icon menu entry like so:

var launchItem = new MenuItem() 
{ 
	Header = "Test",
    Icon = new Image() 
	{ 
		Source = new BitmapImage(new Uri("LogoIcon.ico", UriKind.Relative)) 
	}          
}
launchItem.Click += (o, e) => Logic.OpenEditor("Test2");
TaskbarContextMenu.Items.Add(launchItem);

The icon won't show next to the menu entry. If you use

Icon = new Image() 
{ 
	Source = new BitmapImage(new uri("pack://application:,,,/WpfProject1;component/LogoIcon.ico")) 
}

instead, it does show correctly.

question for external service shutdown

On exiting a service normally, the tray icon will automatically be removed from the system tray, which is good. But I have an external app that auto updates the service by locating the process, performing process.CloseMainwindow() then process.Kill() prior to updating and restarting the service: in this scenario the old icon remains in the system tray until you hover over it, so you will briefly see two icons. Is there some cleaner way in this scenario you could suggest to remove the icon for the old instance from the system tray?

Dispose stream after creating icon?

FYI @punker76 @Lakritzator

I've had this PR from a fellow developer dangling around for quite a while:

grafik

I didn't dispose that stream because the Icon now owns it, which should take care about actually cleaning it up. I obviously can't guarantee that, but by closing it myself right after creating the Icon instance, I might mess things up for the Icon.

OTOH, I was reported potential memory leaks when using the NotifyIcon to do animations. What's your 0.02$ on this?

System.DivideByZeroException: Attempted to divide by zero

I've been receiving automatic crash reports and there are two different ones with DivideByZeroException

System.DivideByZeroException: Attempted to divide by zero.
   at System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size constraint, Nullable`1& lastPageSafeOffset, List`1& previouslyMeasuredOffsets, Nullable`1& lastPagePixelSize, Boolean remeasure)
   at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.DockPanel.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Window.MeasureOverrideHelper(Size constraint)
   at System.Windows.Window.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.Interop.HwndSource.SetLayoutSize()
   at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   at System.Windows.Controls.Primitives.Popup.SetRootVisualToPopupRoot()
   at System.Windows.Controls.Primitives.Popup.CreateWindow(Boolean asyncCall)
   at System.Windows.Controls.Primitives.Popup.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.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.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
   at System.Windows.Controls.Primitives.Popup.CreateRootPopupInternal(Popup popup, UIElement child, Boolean bindTreatMousePlacementAsBottomProperty)
   at System.Windows.Controls.ToolTip.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.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 Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.OnToolTipChange(Boolean visible)
   at Hardcodet.Wpf.TaskbarNotification.Interop.WindowMessageSink.ProcessWindowMessage(UInt32 msg, IntPtr wParam, IntPtr lParam)
   at Hardcodet.Wpf.TaskbarNotification.Interop.WindowMessageSink.OnWindowMessageReceived(IntPtr hWnd, UInt32 messageId, IntPtr wParam, IntPtr lParam)

and another one

System.DivideByZeroException: Attempted to divide by zero.
   at System.Windows.Vector.Normalize()
   at System.Windows.Controls.Primitives.Popup.GetPopupRootLimits(Rect& targetBounds, Rect& screenBounds, Size& limitSize)
   at System.Windows.Controls.Primitives.Popup.RestrictSize(Size desiredSize)
   at System.Windows.Controls.Primitives.PopupRoot.GetPopupSizeRestrictions(Popup popup, Size desiredSize, Boolean& restrictWidth, Boolean& restrictHeight)
   at System.Windows.Controls.Primitives.PopupRoot.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Interop.HwndSource.SetLayoutSize()
   at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   at System.Windows.Controls.Primitives.Popup.SetRootVisualToPopupRoot()
   at System.Windows.Controls.Primitives.Popup.CreateWindow(Boolean asyncCall)
   at System.Windows.Controls.Primitives.Popup.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.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.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
   at System.Windows.Controls.Primitives.Popup.CreateRootPopupInternal(Popup popup, UIElement child, Boolean bindTreatMousePlacementAsBottomProperty)
   at System.Windows.Controls.ContextMenu.HookupParentPopup()
   at System.Windows.Controls.ContextMenu.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.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 Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.ShowContextMenu(Point cursorPosition)
   at Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.OnMouseEvent(MouseEvent me)
   at Hardcodet.Wpf.TaskbarNotification.Interop.WindowMessageSink.ProcessWindowMessage(UInt32 msg, IntPtr wParam, IntPtr lParam)
   at Hardcodet.Wpf.TaskbarNotification.Interop.WindowMessageSink.OnWindowMessageReceived(IntPtr hWnd, UInt32 messageId, IntPtr wParam, IntPtr lParam)

These are from random users so I don't know how to reproduce these.

.Net Core 3.0 support

After using the new csproj format we can now build the assembly also for the new .Net Core 3.0 (Preview).

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.