From 202f1856f6554df4a38c56960d9f808483c8a271 Mon Sep 17 00:00:00 2001 From: Nockiro Date: Tue, 21 Jan 2020 22:15:30 +0100 Subject: [PATCH 1/2] - Added support for windows 10 --- src/BlurMessageBox/BlurWindow.cs | 39 ++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/BlurMessageBox/BlurWindow.cs b/src/BlurMessageBox/BlurWindow.cs index 43e94c0..890f3fc 100644 --- a/src/BlurMessageBox/BlurWindow.cs +++ b/src/BlurMessageBox/BlurWindow.cs @@ -14,16 +14,25 @@ public static class BlurWindows public static void ApplyEffect(this System.Windows.Window win) { // Create new effective objects - var objBlur = new System.Windows.Media.Effects.BlurEffect { Radius = 5 }; - var mask = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.DarkGray) { Opacity = 50 }; + System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect { Radius = 5 }; + System.Windows.Media.SolidColorBrush mask = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.DarkGray) { Opacity = 50 }; // Buffering ... effectBuffer = win.Effect; brushBuffer = win.OpacityMask; - - // Change this.win effective objects - win.Dispatcher.Invoke(new Action(delegate { win.Effect = objBlur; }), System.Windows.Threading.DispatcherPriority.Normal); - win.Dispatcher.Invoke(new Action(delegate { win.OpacityMask = mask; }), System.Windows.Threading.DispatcherPriority.Normal); + + // in windows 10, the dispatcher way doesn't seem to work anymore + if (Environment.OSVersion.Version.Major >= 10) + { + win.Effect = objBlur; + win.OpacityMask = mask; + } + else + { + // Change this.win effective objects + win.Dispatcher.Invoke(new Action(delegate { win.Effect = objBlur; }), System.Windows.Threading.DispatcherPriority.Normal); + win.Dispatcher.Invoke(new Action(delegate { win.OpacityMask = mask; }), System.Windows.Threading.DispatcherPriority.Normal); + } } /// /// Remove Blur Effects @@ -31,10 +40,20 @@ public static void ApplyEffect(this System.Windows.Window win) /// parent window public static void ClearEffect(this System.Windows.Window win) { - // Back changed effective objects - win.Dispatcher.Invoke(new Action(delegate { win.Effect = effectBuffer; }), System.Windows.Threading.DispatcherPriority.Normal); - win.Dispatcher.Invoke(new Action(delegate { win.OpacityMask = brushBuffer; }), System.Windows.Threading.DispatcherPriority.Normal); - win.Dispatcher.Invoke(new Action(delegate { win.Focus(); }), System.Windows.Threading.DispatcherPriority.Normal); + // in windows 10, the dispatcher way doesn't seem to work anymore + if (Environment.OSVersion.Version.Major >= 10) + { + win.Effect = null; + win.OpacityMask = null; + win.Focus(); + } + else + { + // Back changed effective objects + win.Dispatcher.Invoke(new Action(delegate { win.Effect = effectBuffer; }), System.Windows.Threading.DispatcherPriority.Normal); + win.Dispatcher.Invoke(new Action(delegate { win.OpacityMask = brushBuffer; }), System.Windows.Threading.DispatcherPriority.Normal); + win.Dispatcher.Invoke(new Action(delegate { win.Focus(); }), System.Windows.Threading.DispatcherPriority.Normal); + } } } From 5efcf68d6ee2fc76bafc5202ccfc579999d68f2b Mon Sep 17 00:00:00 2001 From: Nockiro Date: Tue, 21 Jan 2020 22:18:59 +0100 Subject: [PATCH 2/2] - Added app.manifest to test projects in order to enable recognition for OS version --- src/BlurMessageBox/BlurMessageBox.csproj | 1 - src/TestWPF/TestWPF.csproj | 4 ++ src/TestWPF/app.manifest | 70 ++++++++++++++++++++++++ src/TestWinForms/TestWinForms.csproj | 1 + src/TestWinForms/app.manifest | 70 ++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 src/TestWPF/app.manifest create mode 100644 src/TestWinForms/app.manifest diff --git a/src/BlurMessageBox/BlurMessageBox.csproj b/src/BlurMessageBox/BlurMessageBox.csproj index e3f2417..f45b0d4 100644 --- a/src/BlurMessageBox/BlurMessageBox.csproj +++ b/src/BlurMessageBox/BlurMessageBox.csproj @@ -119,7 +119,6 @@ Localization.fa-IR.Designer.cs - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/TestWinForms/TestWinForms.csproj b/src/TestWinForms/TestWinForms.csproj index a1e323a..bc6cac6 100644 --- a/src/TestWinForms/TestWinForms.csproj +++ b/src/TestWinForms/TestWinForms.csproj @@ -73,6 +73,7 @@ True + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/src/TestWinForms/app.manifest b/src/TestWinForms/app.manifest new file mode 100644 index 0000000..8e75b4d --- /dev/null +++ b/src/TestWinForms/app.manifest @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +