You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/concepts/TrayIcon.md
+73-14Lines changed: 73 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,27 +7,24 @@ var wm = WindowManager.Get(MyWindow);
7
7
wm.IsVisibleInTray=true;
8
8
```
9
9
10
-
By default, if the user double-clicks this icon, the window is brought to the front, and if minimized, restored.
10
+
By default, if the user clicks/selects this icon, the window is brought to the front, and if minimized, restored.
11
11
The icon used is obtained from the Window's task bar icon. You can set the icon using the `Window.AppWindow.SetTaskbarIcon` method.
12
12
13
13
### Context menu and custom click actions
14
-
You can add additional actions to user-inactions by subscribing to the [`TrayIconInvoked`](https://dotmorten.github.io/WinUIEx/api/WinUIEx.WindowManager.TrayIconInvoked.html) event.
15
-
This event gives you the ability override the default double-click action by marking the event handled,
16
-
or adding any kind of flyout by setting the [`Flyout`](https://dotmorten.github.io/WinUIEx/api/WinUIEx.TrayIconInvokedEventArgs.Flyout.html#WinUIEx_TrayIconInvokedEventArgs_Flyout) property on the event argument.
14
+
You can add additional actions to user-inactions by subscribing to the [`TrayIconContextMenu`](https://dotmorten.github.io/WinUIEx/api/WinUIEx.WindowManager.TrayIconContextMenu.html) event.
15
+
This event gives you the ability override the display any kind of flyout by setting the
16
+
[`Flyout`](https://dotmorten.github.io/WinUIEx/api/WinUIEx.TrayIconEventArgs.Flyout.html#TrayIconEventArgs) property on the event argument.
@@ -51,4 +48,66 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar
51
48
else
52
49
_window.Activate();
53
50
}
51
+
```
52
+
53
+
## Using the TrayIcon class
54
+
55
+
For more fine-grained control over the tray icon, you can use the [`TrayIcon`](https://dotmorten.github.io/WinUIEx/api/WinUIEx.TrayIcon.html) class directly.
56
+
This class allows you to create a tray icon without associating it with a window, and gives you more control over its behavior,
57
+
updating its icon and tooltip, or even have multiple icons for a single process.
58
+
59
+
Note: Make sure once you close your application, that all TrayIcon instances are disposed, otherwise the icon will remain in the tray and the process will not exit.
60
+
This behavior however also allows you to create a window-less application, or (if needed) creating a Window on demand based on TrayIcon interactions. For example:
61
+
62
+
```cs
63
+
publicpartialclassApp : Application
64
+
{
65
+
privateTrayIconicon;
66
+
privateWindow? _window;
67
+
68
+
publicApp()
69
+
{
70
+
InitializeComponent();
71
+
}
72
+
73
+
privateWindowGetMainWindow()
74
+
{
75
+
if (_windowisnotnull)
76
+
return_window;
77
+
_window=newMainWindow();
78
+
_window.AppWindow.Closing+= (s, e) =>
79
+
{
80
+
// Prevent closing so it can be re-activated later. We'll just hide it for now
81
+
// As an alternative don't cache the Window, but close and recreate a new Window every time.
/// <para><see href="https://docs.microsoft.com/windows/win32/api//shellapi/ns-shellapi-notifyicondataw#members">Read more on docs.microsoft.com</see>.</para>
307
311
/// </summary>
308
312
internal__ushort_256szInfo;
309
-
internal_Anonymous_e__UnionAnonymous;
313
+
internaluintVersionOrTimeout;
310
314
/// <summary>
311
315
/// <para>Type: <b>TCHAR[64]</b></para>
312
316
/// <para><b>Windows 2000 and later</b>. A null-terminated string that specifies a title for a balloon notification. This title appears in a larger font immediately above the text. It can have a maximum of 64 characters, including the terminating null character, but should be restricted to 48 characters in English to accommodate localization.</para>
/// <para><see href="https://docs.microsoft.com/windows/win32/api//shellapi/ns-shellapi-notifyicondataw#members">Read more on docs.microsoft.com</see>.</para>
455
449
/// </summary>
456
450
internal__ushort_256szInfo;
457
-
internal_Anonymous_e__UnionAnonymous;
451
+
internaluintVersionOrTimeout;
458
452
/// <summary>
459
453
/// <para>Type: <b>TCHAR[64]</b></para>
460
454
/// <para><b>Windows 2000 and later</b>. A null-terminated string that specifies a title for a balloon notification. This title appears in a larger font immediately above the text. It can have a maximum of 64 characters, including the terminating null character, but should be restricted to 48 characters in English to accommodate localization.</para>
/// <para><see href="https://docs.microsoft.com/windows/win32/api//shellapi/ns-shellapi-notifyicondataw#members">Read more on docs.microsoft.com</see>.</para>
0 commit comments