From 5fd37e97fb126bc0ee8eeaa0ddb3051b33761cad Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Fri, 31 May 2019 22:49:37 +0800 Subject: [PATCH] Update NotifyIcon.cs --- .../Controls/Other/NotifyIcon.cs | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs index fc87cbb4..25098b63 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs @@ -85,21 +85,7 @@ namespace HandyControl.Controls _id = ++NextId; _callback = Callback; - Loaded += (s, e) => - { - RegisterClass(); - if (Visibility == Visibility.Visible) - { - OnIconChanged(); - UpdateIcon(true); - } - - _dispatcherTimerPos = new DispatcherTimer - { - Interval = TimeSpan.FromMilliseconds(200) - }; - _dispatcherTimerPos.Tick += DispatcherTimerPos_Tick; - }; + Loaded += (s, e) => Init(); if (Application.Current != null) Application.Current.Exit += (s, e) => Dispose(); } @@ -109,6 +95,22 @@ namespace HandyControl.Controls Dispose(false); } + public void Init() + { + RegisterClass(); + if (Visibility == Visibility.Visible) + { + OnIconChanged(); + UpdateIcon(true); + } + + _dispatcherTimerPos = new DispatcherTimer + { + Interval = TimeSpan.FromMilliseconds(200) + }; + _dispatcherTimerPos.Tick += DispatcherTimerPos_Tick; + } + public static readonly DependencyProperty TextProperty = DependencyProperty.Register( "Text", typeof(string), typeof(NotifyIcon), new PropertyMetadata(default(string)));