Skip to content

Commit

Permalink
fix(notifyicon): Fix the issue of the context menu of the tray progra…
Browse files Browse the repository at this point in the history
…m not dynamically refreshing the theme.
  • Loading branch information
ZGGSONG committed Jan 18, 2024
1 parent 98e62f6 commit b75438f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 9 additions & 3 deletions STranslate/Views/NotifyIcon.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
<proxy:BindingProxy x:Key="NotifyIcon" Data="{Binding ElementName=notifyIcon}" />
<proxy:BindingProxy x:Key="MainView" Data="{Binding RelativeSource={RelativeSource AncestorType=Window}}" />
</UserControl.Resources>
<tb:TaskbarIcon DoubleClickCommand="{Binding DoubleClickCommand}"
<tb:TaskbarIcon x:Name="TrayIcon"
DoubleClickCommand="{Binding DoubleClickCommand}"
DoubleClickCommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}"
IconSource="{Binding NIModel.IconSource}"
ToolTipText="{Binding NIModel.ToolTip}">
ToolTipText="{Binding NIModel.ToolTip}"
TrayContextMenuOpen="TrayIcon_TrayContextMenuOpen">
<tb:TaskbarIcon.ContextMenu>
<!-- // 编译出来似乎有点显示Bug,再手动指定一下DataContext // -->
<ContextMenu Width="150" d:DataContext="{d:DesignInstance Type=vm:NotifyIconViewModel}" DataContext="{Binding Source={StaticResource NotifyIcon}, Path=Data.DataContext}">
<ContextMenu x:Name="TrayIconContextMenu"
Width="150"
d:DataContext="{d:DesignInstance Type=vm:NotifyIconViewModel}"
DataContext="{Binding Source={StaticResource NotifyIcon}, Path=Data.DataContext}"
FontFamily="{DynamicResource UserFont}">

<MenuItem Command="{Binding InputTranslateCommand}"
CommandParameter="{Binding Source={StaticResource MainView}, Path=Data}"
Expand Down
13 changes: 12 additions & 1 deletion STranslate/Views/NotifyIcon.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows.Controls;
using System.Windows;
using System.Windows.Controls;

namespace STranslate.Views
{
Expand All @@ -11,5 +12,15 @@ public NotifyIcon()
{
InitializeComponent();
}

/// <summary>
/// https://github.com/hardcodet/wpf-notifyicon/issues/19
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TrayIcon_TrayContextMenuOpen(object sender, RoutedEventArgs e)
{
TrayIconContextMenu.UpdateDefaultStyle();
}
}
}

0 comments on commit b75438f

Please sign in to comment.