fix: Make NotifyIcon contextmenu display properly#1534
Merged
pomianowski merged 1 commit intolepoco:mainfrom Nov 7, 2025
Merged
fix: Make NotifyIcon contextmenu display properly#1534pomianowski merged 1 commit intolepoco:mainfrom
NotifyIcon contextmenu display properly#1534pomianowski merged 1 commit intolepoco:mainfrom
Conversation
7 tasks
Contributor
Author
|
use x:Name=MainWindow is better, but i want less code. |
chucker
reviewed
Sep 11, 2025
| TooltipText="WPF UI Gallery"> | ||
| <tray:NotifyIcon.Menu> | ||
| <ContextMenu ItemsSource="{Binding ViewModel.TrayMenuItems, Mode=OneWay}" /> | ||
| <ContextMenu DataContext="{Binding DataContext, Source={x:Reference NavigationView}}" ItemsSource="{Binding ViewModel.TrayMenuItems, Mode=OneWay}" /> |
Collaborator
There was a problem hiding this comment.
I think x:Reference is discouraged, but I'm only not sure after reading https://learn.microsoft.com/en-us/dotnet/desktop/xaml-services/xreference-markup-extension#xreference-and-wpf.
Contributor
Author
There was a problem hiding this comment.
<tray:NotifyIcon
FocusOnLeftClick="True"
MenuOnRightClick="True">
<tray:NotifyIcon.Resources>
<DiscreteObjectKeyFrame x:Key="proxy" Value="{Binding}"/>
</tray:NotifyIcon.Resources>
<tray:NotifyIcon.Menu>
<ContextMenu DataContext="{Binding Source={StaticResource proxy},Path=Value}">
<ui:MenuItem
Name="OpenSettings"
Command="{Binding OpenSettingsCommand}"
CommandParameter="123"
Header="{x:Static str:Resources.AppSetting}" />
<ui:MenuItem
Name="Exit"
Command="{Binding ExitAppCommand}"
Header="{x:Static str:Resources.AppExit}" />
</ContextMenu>
</tray:NotifyIcon.Menu>
</tray:NotifyIcon>ok,i have plan b
Contributor
Author
There was a problem hiding this comment.
@chucker
I have provided two of my common practices. My approach is to solve it through XAML:
- Using x:Referenceto traverse the visual tree.
- Using a lazy-loading object (I directly borrowed the DiscreteObjectKeyFramefrom the WPF animation system).
Can we discuss your thoughts? What fixes are planned?
Maybe we could start by getting something done, even if it's not the final solution? The Wpf.Ui.Gallery is a sample project, so we can always change it later if we think of a better way.
Open
NotifyIcon contextmenu display properly
pomianowski
approved these changes
Nov 7, 2025
This was referenced Nov 24, 2025
This was referenced Dec 2, 2025
This was referenced Dec 22, 2025
This was referenced Dec 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
Issue Number: N/A
NotifyIcon's ContextMenu not display
What is the new behavior?
Other information
The context menu isn't part of the same visual tree and therefore doesn't have the same DataContext.
I have provided a tip here to solve this problem.