Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
MenuOnRightClick="True"
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

Copy link
Author

Choose a reason for hiding this comment

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

@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.

</tray:NotifyIcon.Menu>
</tray:NotifyIcon>
</Grid>
Expand Down
Loading