lepoco / lepoco/wpfui

Access NotifyIconService from NotifyIcon

Open
#345 1 comment 0 reactions 1 assignee View on GitHub

@pomianowski is already working on this.

Since Aug 12, 2022.

controls enhancement
Dominant language
C#
Stars
9.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

I am trying to have a left click on the NotifyIcon behave like the right click does (I want it to show the context menu but do it in a way where it disappears when you click elsewhere like on the Desktop). Setting the IsOpen on that ContextMenu opens it, but it never disappears in that case (I tried using LostFocus but that doesn't work if you click say, the desktop). In searching through the source code I saw how the right click worked, but didn't have access to the underlying plumbing to make what I wanted to happen work.

I used this witchcraft to reflect on the non public members but it seems like I'll shoot myself in the foot with this approach (which I'm not beyond doing).

  FieldInfo? fi = NotifyIcon.GetType().GetField("_notifyIconService", BindingFlags.NonPublic | BindingFlags.Instance);
  object? notifyIconService = fi?.GetValue(NotifyIcon);
  MethodInfo? openMenu = notifyIconService?.GetType().GetMethod("OpenMenu", BindingFlags.NonPublic | BindingFlags.Instance);
  openMenu?.Invoke(notifyIconService, null);

My question is, can some of these private members be surfaced in a way that allows the caller some more options to tweak.

P.S. Your library is absolutely amazing. I love it. Much respect.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.