From 7785664a5e25f9ac2e24f337e658f11f40b78619 Mon Sep 17 00:00:00 2001 From: Bastian Schmidt Date: Sat, 11 Jun 2016 23:16:58 +0200 Subject: [PATCH] Fixes #325 by checking access to the application main thread --- Changelog.md | 1 + Fluent.Ribbon/Controls/RibbonTabItem.cs | 2 +- Fluent.Ribbon/Converters/IconConverter.cs | 4 +++- Fluent.Ribbon/Converters/ObjectToImageConverter.cs | 11 +++++++---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index 38d279963..3484c3994 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,7 @@ - [#305](../../issues/305) - Combobox items will be drawn above each other on scroll down - [#311](../../issues/311) - State loading too verbose - [#315](../../issues/315) - Menu button gets blurry + - [#325](../../issues/325) - Running RibbonWindow not on the main thread. - ### Enhancements - [#279](../../issues/279) - Localization of ColorGallery diff --git a/Fluent.Ribbon/Controls/RibbonTabItem.cs b/Fluent.Ribbon/Controls/RibbonTabItem.cs index 61d34e815..9e0bd6abf 100644 --- a/Fluent.Ribbon/Controls/RibbonTabItem.cs +++ b/Fluent.Ribbon/Controls/RibbonTabItem.cs @@ -718,7 +718,7 @@ public void OnKeyTipPressed() this.IsSelected = true; // This way keytips for delay loaded elements work correctly. Partially fixes #244. - Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new Action(delegate { })); + this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new Action(delegate { })); } /// diff --git a/Fluent.Ribbon/Converters/IconConverter.cs b/Fluent.Ribbon/Converters/IconConverter.cs index bacc8d5eb..a1e6c8b0a 100644 --- a/Fluent.Ribbon/Converters/IconConverter.cs +++ b/Fluent.Ribbon/Converters/IconConverter.cs @@ -22,7 +22,9 @@ object IValueConverter.Convert(object value, Type targetType, object parameter, if (value == null) { if (Application.Current != null - && Application.Current.MainWindow != null) + && Application.Current.CheckAccess() + && Application.Current.MainWindow != null + && Application.Current.MainWindow.CheckAccess()) { try { diff --git a/Fluent.Ribbon/Converters/ObjectToImageConverter.cs b/Fluent.Ribbon/Converters/ObjectToImageConverter.cs index bdd5fb9dd..946704889 100644 --- a/Fluent.Ribbon/Converters/ObjectToImageConverter.cs +++ b/Fluent.Ribbon/Converters/ObjectToImageConverter.cs @@ -90,9 +90,9 @@ private static Image CreateImage(string imagePath, double desiredSize) && imagePath.EndsWith(".ico")) { return new Image - { - Source = ExtractImageFromIcoFile(imagePath, desiredSize) - }; + { + Source = ExtractImageFromIcoFile(imagePath, desiredSize) + }; } return new Image @@ -160,7 +160,10 @@ private static ImageSource ExtractImage(BitmapDecoder decoder, double desiredSiz { var dpiFactor = 1.0; - if (Application.Current.MainWindow != null) + if (Application.Current != null + && Application.Current.CheckAccess() + && Application.Current.MainWindow != null + && Application.Current.MainWindow.CheckAccess()) { // dpi.M11 = dpiX, dpi.M22 = dpiY var presentationSource = PresentationSource.FromVisual(Application.Current.MainWindow);