Skip to content

fix: tray context menu commands + ForceCreate race condition - #6

Merged
pexatar merged 1 commit into
mainfrom
fix/tray-commands
Mar 20, 2026
Merged

pexatar merged 1 commit into
mainfrom
fix/tray-commands

Conversation

@pexatar

@pexatar pexatar commented Mar 20, 2026

Copy link
Copy Markdown
Owner
  • Replace Click event handlers on MenuFlyoutItem with x:Bind Command. H.NotifyIcon shows the flyout in a separate popup context; XAML event routing does not reach MainWindow handlers from there. RelayCommand via x:Bind resolves at compile-time on the MainWindow instance and is invoked directly — same pattern as DoubleClickCommand (confirmed working). TrayShowCommand / TrayLockCommand / TrayExitCommand.

  • Add HideToTray(): calls TrayIcon.ForceCreate() before AppWindow.Hide() to fix race condition where AppWindow.Hide() fired before the XAML visual tree loaded, preventing Shell_NotifyIcon from ever registering.

Description

Brief description of the changes in this PR.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)

Testing

Describe the tests you ran to verify your changes.

  • All existing tests pass (dotnet test)
  • New tests added for new functionality
  • Solution builds without warnings (dotnet build PassKey.sln -p:Platform=x64)

Checklist

  • My code follows the project's code style guidelines
  • I have added XML documentation to all new public types and members
  • I have updated the CHANGELOG.md if applicable
  • My changes do not introduce new compiler warnings

- Replace Click event handlers on MenuFlyoutItem with x:Bind Command.
  H.NotifyIcon shows the flyout in a separate popup context; XAML event
  routing does not reach MainWindow handlers from there. RelayCommand
  via x:Bind resolves at compile-time on the MainWindow instance and
  is invoked directly — same pattern as DoubleClickCommand (confirmed
  working). TrayShowCommand / TrayLockCommand / TrayExitCommand.

- Add HideToTray(): calls TrayIcon.ForceCreate() before AppWindow.Hide()
  to fix race condition where AppWindow.Hide() fired before the XAML
  visual tree loaded, preventing Shell_NotifyIcon from ever registering.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pexatar
pexatar merged commit 17be628 into main Mar 20, 2026
1 check passed
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.

1 participant