From 837a8ad04e9c2421b9d218d94c65e0f6e56759f2 Mon Sep 17 00:00:00 2001 From: lwq Date: Thu, 26 Nov 2020 13:46:18 +0800 Subject: [PATCH 1/2] fixd using FatalGlobal not in dispather caused attempt to access control and throw an UnvalidOprationException --- .../HandyControl_Shared/Controls/Growl/Growl.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Growl/Growl.cs b/src/Shared/HandyControl_Shared/Controls/Growl/Growl.cs index 19f4ee51..0e1842a6 100644 --- a/src/Shared/HandyControl_Shared/Controls/Growl/Growl.cs +++ b/src/Shared/HandyControl_Shared/Controls/Growl/Growl.cs @@ -485,7 +485,19 @@ namespace HandyControl.Controls growlInfo.IconBrushKey = ResourceToken.PrimaryTextBrush; growlInfo.StaysOpen = true; growlInfo.ShowCloseButton = false; - if (GrowlPanel.ContextMenu != null) GrowlPanel.ContextMenu.Opacity = 0; + Application.Current.Dispatcher?.Invoke( +#if NET40 + new Action( +#endif + () => + { + if (GrowlPanel.ContextMenu != null) GrowlPanel.ContextMenu.Opacity = 0; + } + +#if NET40 + ) +#endif + ); } else { From 57f500bcf7a6871607d387b5868842d6d39149d5 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Thu, 26 Nov 2020 22:59:59 +0800 Subject: [PATCH 2/2] Update Growl.cs --- .../Controls/Growl/Growl.cs | 99 +++++++++---------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Growl/Growl.cs b/src/Shared/HandyControl_Shared/Controls/Growl/Growl.cs index 0e1842a6..337ad319 100644 --- a/src/Shared/HandyControl_Shared/Controls/Growl/Growl.cs +++ b/src/Shared/HandyControl_Shared/Controls/Growl/Growl.cs @@ -353,28 +353,28 @@ namespace HandyControl.Controls new Action( #endif () => + { + var ctl = new Growl { - var ctl = new Growl - { - Message = growlInfo.Message, - Time = DateTime.Now, - Icon = ResourceHelper.GetResource(growlInfo.IconKey), - IconBrush = ResourceHelper.GetResource(growlInfo.IconBrushKey), - _showCloseButton = growlInfo.ShowCloseButton, - ActionBeforeClose = growlInfo.ActionBeforeClose, - _staysOpen = growlInfo.StaysOpen, - ShowDateTime = growlInfo.ShowDateTime, - ConfirmStr = growlInfo.ConfirmStr, - CancelStr = growlInfo.CancelStr, - Type = growlInfo.Type, - _waitTime = Math.Max(growlInfo.WaitTime, 2) - }; - GrowlWindow.GrowlPanel.Children.Insert(0, ctl); - } + Message = growlInfo.Message, + Time = DateTime.Now, + Icon = ResourceHelper.GetResource(growlInfo.IconKey), + IconBrush = ResourceHelper.GetResource(growlInfo.IconBrushKey), + _showCloseButton = growlInfo.ShowCloseButton, + ActionBeforeClose = growlInfo.ActionBeforeClose, + _staysOpen = growlInfo.StaysOpen, + ShowDateTime = growlInfo.ShowDateTime, + ConfirmStr = growlInfo.ConfirmStr, + CancelStr = growlInfo.CancelStr, + Type = growlInfo.Type, + _waitTime = Math.Max(growlInfo.WaitTime, 2) + }; + GrowlWindow.GrowlPanel.Children.Insert(0, ctl); + } #if NET40 - ) + ) #endif - ); + ); } /// @@ -386,40 +386,40 @@ namespace HandyControl.Controls Application.Current.Dispatcher?.Invoke( #if NET40 new Action( -#endif +#endif () => + { + var ctl = new Growl { - var ctl = new Growl + Message = growlInfo.Message, + Time = DateTime.Now, + Icon = ResourceHelper.GetResource(growlInfo.IconKey), + IconBrush = ResourceHelper.GetResource(growlInfo.IconBrushKey), + _showCloseButton = growlInfo.ShowCloseButton, + ActionBeforeClose = growlInfo.ActionBeforeClose, + _staysOpen = growlInfo.StaysOpen, + ShowDateTime = growlInfo.ShowDateTime, + ConfirmStr = growlInfo.ConfirmStr, + CancelStr = growlInfo.CancelStr, + Type = growlInfo.Type, + _waitTime = Math.Max(growlInfo.WaitTime, 2) + }; + if (!string.IsNullOrEmpty(growlInfo.Token)) + { + if (PanelDic.TryGetValue(growlInfo.Token, out var panel)) { - Message = growlInfo.Message, - Time = DateTime.Now, - Icon = ResourceHelper.GetResource(growlInfo.IconKey), - IconBrush = ResourceHelper.GetResource(growlInfo.IconBrushKey), - _showCloseButton = growlInfo.ShowCloseButton, - ActionBeforeClose = growlInfo.ActionBeforeClose, - _staysOpen = growlInfo.StaysOpen, - ShowDateTime = growlInfo.ShowDateTime, - ConfirmStr = growlInfo.ConfirmStr, - CancelStr = growlInfo.CancelStr, - Type = growlInfo.Type, - _waitTime = Math.Max(growlInfo.WaitTime, 2) - }; - if (!string.IsNullOrEmpty(growlInfo.Token)) - { - if (PanelDic.TryGetValue(growlInfo.Token, out var panel)) - { - panel?.Children.Insert(0, ctl); - } - } - else - { - GrowlPanel?.Children.Insert(0, ctl); + panel?.Children.Insert(0, ctl); } } + else + { + GrowlPanel?.Children.Insert(0, ctl); + } + } #if NET40 - ) + ) #endif - ); + ); } private static void InitGrowlInfo(ref GrowlInfo growlInfo, InfoType infoType) @@ -491,13 +491,12 @@ namespace HandyControl.Controls #endif () => { - if (GrowlPanel.ContextMenu != null) GrowlPanel.ContextMenu.Opacity = 0; + if (GrowlPanel.ContextMenu != null) GrowlPanel.ContextMenu.Opacity = 0; } - #if NET40 - ) + ) #endif - ); + ); } else {