Skip to content

Conversation

IOL0ol1
Copy link

@IOL0ol1 IOL0ol1 commented Sep 11, 2025

Pull request type

Please check the type of change your PR introduces:

  • Update
  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes

What is the current behavior?

Issue Number: N/A

NotifyIcon's ContextMenu not display

What is the new behavior?

  • now we can see the NotifyIcon's ContextMenu

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.

@github-actions github-actions bot added PR Pull request gallery WPF UI Gallery release labels Sep 11, 2025
@IOL0ol1
Copy link
Author

IOL0ol1 commented Sep 11, 2025

use x:Name=MainWindow is better, but i want less code.

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}" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Author

Choose a reason for hiding this comment

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

   <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

@maihcx maihcx mentioned this pull request Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gallery WPF UI Gallery PR Pull request release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants