Skip to content

Conversation

@logiclrd
Copy link
Contributor

@logiclrd logiclrd commented Jun 19, 2024

What does the pull request do?

Adds a sample application demonstrating the use of <TrayIcon> in App.axaml, including an associated menu.

TrayIcon.csproj optimistically references as-yet-nonexistent version 11.2.0 of Avalonia, in the hopes that it will include the bug fix for crashing when activating tray icon menu items.

UPDATE: 11.2.0 did indeed fix the problem, but this PR went to sleep for a while and now 11.3.8 is out.

Scope of this PR:

  • fix or update to an existing sample
  • add a new sample

Checklist

If this is a new Sample

In any case

  • Spell-checking done
  • Checked if all hyperlinks work
  • Checked if all images are visible

@maxkatz6 maxkatz6 requested a review from timunie June 19, 2024 23:22
@logiclrd logiclrd mentioned this pull request Jun 27, 2024
@timunie
Copy link
Collaborator

timunie commented Nov 16, 2025

Hey @logiclrd,

I really have to apologize for not responding earlier. I wanted to wait for AvaloniaUI/Avalonia#7880 to be fixed but this seems to be more complicated than thought. Moreover your sample gave me some NRE that I didn't understand until today. And tbh, I forgot about this PR for quite a while.

Today I figured out that binding either directly to void or using RelayCommand will solve the NRE. So I think it's time to re-activate this PR.

…tray icon (on supported platforms):

- Updated AboutWindow.axaml to include a Label indicating how it was activated. Added method SetActivationMode to AboutWindow.axaml. Added enumerated type ActivationMode.cs.
- Updated the ShowAboutWindow command handler method in App.axaml.cs to call AboutWindow.SetActivationMode.
- Added command ClickedCommand with handler method Clicked to App.axaml.cs.
- Updated App.axaml to wire up TrayIcon.Command to ClickedCommand.
@logiclrd
Copy link
Contributor Author

Awesome 🙂 I've merged the latest in from the mainline, updated the changes here to follow changes to the README.adoc conventions that took place in the meantime, and then also updated the sample in a couple of small ways:

  • It now also hooks the generalized "click" event, and the About window indicates how it was activated.
  • The TrayIcon readme includes a small screenshot, since when the TrayIcon sample is run, the only visual change is the tray icon popping into the notification area, and that could be easily overlooked if the user doesn't know what they're looking for.

There was also a mistake in the directory name in the link from README.adoc to the TrayIcon sample.

I have verified that the changes to the .sln are correct using Visual Studio 2026.

@logiclrd
Copy link
Contributor Author

Should I bump the references to Avalonia NuGet packages to a newer version? I'm sort of conflicted about this, because on the one hand, most of them are at the latest release version, but it's not 100% consistent and the version numbers that are there now happen to be the first version in which the sample runs properly.

But the majority of the samples are using 11.3.8, so the ones that aren't are probably just outliers that should be using 11.3.8. I'll bump the references. 🙂

@logiclrd logiclrd force-pushed the JDG_TrayIconSampleApp branch from 8e97e0f to b57a56e Compare November 16, 2025 18:29
@logiclrd
Copy link
Contributor Author

Let me know if any other changes are needed. 🙂

Copy link
Collaborator

@timunie timunie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only these two comments to fix, otherwise it looks good to merge.

… directly instead of ReactiveCommand. Replaced the NuGet reference to Avalonia.ReactiveUI with one to CommunityToolkit.Mvvm.

Updated ExitApplication in App.axaml.cs to use TryShutdown instead of Shutdown where possible, and to support IControlledApplicationLifetime if the current lifetime isn't an IClassicDesktopStyleApplicationLifetime.
Made the names of the commands in App.axaml/.axaml.cs more descriptive.
@timunie
Copy link
Collaborator

timunie commented Nov 16, 2025

LGTM.

THX 🙏

@timunie
Copy link
Collaborator

timunie commented Nov 16, 2025

Okay I screwed up now, so don't worry your changes have been merged just from the wrong branch 🙈

@timunie timunie closed this Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants