diff --git a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs index df412053..37e42a30 100644 --- a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs @@ -45,8 +45,7 @@ public partial class StatusBarView : ReactiveUserControl ViewModel.DispatcherRefreshIconInteraction.RegisterHandler(interaction => { - Dispatcher.UIThread.Post(RefreshIcon, - DispatcherPriority.Default); + Dispatcher.UIThread.Post(RefreshIcon, DispatcherPriority.Default); interaction.SetOutput(Unit.Default); }).DisposeWith(disposables); }); @@ -57,6 +56,9 @@ public partial class StatusBarView : ReactiveUserControl { cmbSystemProxy.Items.RemoveAt(cmbSystemProxy.Items.Count - 1); } + + // Because this view has not yet been initialized when DispatcherRefreshIconInteraction is first called. + RefreshIcon(); } private void RefreshIcon() diff --git a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs index 333912ac..6a6db3aa 100644 --- a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs +++ b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs @@ -71,16 +71,18 @@ public partial class StatusBarView ViewModel.DispatcherRefreshIconInteraction.RegisterHandler(interaction => { - Application.Current?.Dispatcher.Invoke(async () => - { - tbNotify.Icon = await WindowsManager.Instance.GetNotifyIcon(_config); - Application.Current.MainWindow?.Icon = WindowsManager.Instance.GetAppIcon(_config); - }, DispatcherPriority.Normal); + Application.Current?.Dispatcher.Invoke(async () => await RefreshIcon(), DispatcherPriority.Normal); interaction.SetOutput(Unit.Default); }).DisposeWith(disposables); }); } + private async Task RefreshIcon() + { + tbNotify.Icon = await WindowsManager.Instance.GetNotifyIcon(_config); + Application.Current.MainWindow?.Icon = WindowsManager.Instance.GetAppIcon(_config); + } + private async void menuExit_Click(object sender, RoutedEventArgs e) { tbNotify.Dispose();