From 74829a5e1f8ed927585cd0cd7c1c3a215f4d9702 Mon Sep 17 00:00:00 2001 From: punker76 Date: Tue, 7 Jul 2020 12:03:21 +0200 Subject: [PATCH 1/2] (GH-3872) Execute ThemeManager changes at the current Dispatcher UI thread --- src/MahApps.Metro/Behaviors/TiltBehavior.cs | 2 +- .../Controls/Dialogs/BaseMetroDialog.cs | 2 +- src/MahApps.Metro/Controls/Flyout.cs | 52 +++++++++---------- src/MahApps.Metro/Controls/MetroWindow.cs | 44 ++++++++-------- 4 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/MahApps.Metro/Behaviors/TiltBehavior.cs b/src/MahApps.Metro/Behaviors/TiltBehavior.cs index c70b44c1b3..d321d9f251 100644 --- a/src/MahApps.Metro/Behaviors/TiltBehavior.cs +++ b/src/MahApps.Metro/Behaviors/TiltBehavior.cs @@ -116,7 +116,7 @@ protected override void OnAttached() private void ThemeManagerIsThemeChanged(object sender, ThemeChangedEventArgs e) { - this.RotatorParent?.Refresh(); + this.Invoke(() => { this.RotatorParent?.Refresh(); }); } protected override void OnDetaching() diff --git a/src/MahApps.Metro/Controls/Dialogs/BaseMetroDialog.cs b/src/MahApps.Metro/Controls/Dialogs/BaseMetroDialog.cs index c4b70219f6..309311903b 100644 --- a/src/MahApps.Metro/Controls/Dialogs/BaseMetroDialog.cs +++ b/src/MahApps.Metro/Controls/Dialogs/BaseMetroDialog.cs @@ -243,7 +243,7 @@ private void BaseMetroDialogUnloaded(object sender, RoutedEventArgs e) private void ThemeManagerIsThemeChanged(object sender, ThemeChangedEventArgs e) { - this.HandleThemeChange(); + this.Invoke(this.HandleThemeChange); } private static object TryGetResource(ControlzEx.Theming.Theme theme, string key) diff --git a/src/MahApps.Metro/Controls/Flyout.cs b/src/MahApps.Metro/Controls/Flyout.cs index b01390de13..72533ba061 100644 --- a/src/MahApps.Metro/Controls/Flyout.cs +++ b/src/MahApps.Metro/Controls/Flyout.cs @@ -66,13 +66,13 @@ public event RoutedEventHandler ClosingFinished public static readonly DependencyProperty IsPinnedProperty = DependencyProperty.Register(nameof(IsPinned), typeof(bool), typeof(Flyout), new PropertyMetadata(BooleanBoxes.TrueBox)); public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(nameof(IsOpen), typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsOpenedChanged)); public static readonly DependencyProperty AnimateOnPositionChangeProperty = DependencyProperty.Register(nameof(AnimateOnPositionChange), typeof(bool), typeof(Flyout), new PropertyMetadata(BooleanBoxes.TrueBox)); - public static readonly DependencyProperty AnimateOpacityProperty = DependencyProperty.Register(nameof(AnimateOpacity), typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, AnimateOpacityChanged)); + public static readonly DependencyProperty AnimateOpacityProperty = DependencyProperty.Register(nameof(AnimateOpacity), typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, OnAnimateOpacityPropertyChanged)); public static readonly DependencyProperty IsModalProperty = DependencyProperty.Register(nameof(IsModal), typeof(bool), typeof(Flyout), new PropertyMetadata(BooleanBoxes.FalseBox)); public static readonly DependencyProperty CloseCommandProperty = DependencyProperty.RegisterAttached(nameof(CloseCommand), typeof(ICommand), typeof(Flyout), new UIPropertyMetadata(null)); public static readonly DependencyProperty CloseCommandParameterProperty = DependencyProperty.Register(nameof(CloseCommandParameter), typeof(object), typeof(Flyout), new PropertyMetadata(null)); - public static readonly DependencyProperty ThemeProperty = DependencyProperty.Register(nameof(Theme), typeof(FlyoutTheme), typeof(Flyout), new FrameworkPropertyMetadata(FlyoutTheme.Dark, ThemeChanged)); + public static readonly DependencyProperty ThemeProperty = DependencyProperty.Register(nameof(Theme), typeof(FlyoutTheme), typeof(Flyout), new FrameworkPropertyMetadata(FlyoutTheme.Dark, OnThemePropertyChanged)); public static readonly DependencyProperty ExternalCloseButtonProperty = DependencyProperty.Register(nameof(ExternalCloseButton), typeof(MouseButton), typeof(Flyout), new PropertyMetadata(MouseButton.Left)); public static readonly DependencyProperty CloseButtonVisibilityProperty = DependencyProperty.Register(nameof(CloseButtonVisibility), typeof(Visibility), typeof(Flyout), new FrameworkPropertyMetadata(Visibility.Visible)); public static readonly DependencyProperty CloseButtonIsCancelProperty = DependencyProperty.Register(nameof(CloseButtonIsCancel), typeof(bool), typeof(Flyout), new PropertyMetadata(BooleanBoxes.FalseBox)); @@ -518,22 +518,23 @@ private static void IsAutoCloseEnabledChanged(DependencyObject dependencyObject, { var flyout = (Flyout)dependencyObject; - Action autoCloseEnabledChangedAction = () => { - if (e.NewValue != e.OldValue) + Action autoCloseEnabledChangedAction = () => { - if ((bool)e.NewValue) + if (e.NewValue != e.OldValue) { - if (flyout.IsOpen) + if ((bool)e.NewValue) { - flyout.StartAutoCloseTimer(); + if (flyout.IsOpen) + { + flyout.StartAutoCloseTimer(); + } + } + else + { + flyout.StopAutoCloseTimer(); } } - else - { - flyout.StopAutoCloseTimer(); - } - } - }; + }; flyout.Dispatcher.BeginInvoke(DispatcherPriority.Background, autoCloseEnabledChangedAction); } @@ -542,16 +543,17 @@ private static void AutoCloseIntervalChanged(DependencyObject dependencyObject, { var flyout = (Flyout)dependencyObject; - Action autoCloseIntervalChangedAction = () => { - if (e.NewValue != e.OldValue) + Action autoCloseIntervalChangedAction = () => { - flyout.InitializeAutoCloseTimer(); - if (flyout.IsAutoCloseEnabled && flyout.IsOpen) + if (e.NewValue != e.OldValue) { - flyout.StartAutoCloseTimer(); + flyout.InitializeAutoCloseTimer(); + if (flyout.IsAutoCloseEnabled && flyout.IsOpen) + { + flyout.StartAutoCloseTimer(); + } } - } - }; + }; flyout.Dispatcher.BeginInvoke(DispatcherPriority.Background, autoCloseIntervalChangedAction); } @@ -627,16 +629,14 @@ private void TryFocusElement() } } - private static void ThemeChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) + private static void OnThemePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { - var flyout = (Flyout)dependencyObject; - flyout.UpdateFlyoutTheme(); + (dependencyObject as Flyout)?.UpdateFlyoutTheme(); } - private static void AnimateOpacityChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) + private static void OnAnimateOpacityPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { - var flyout = (Flyout)dependencyObject; - flyout.UpdateOpacityChange(); + (dependencyObject as Flyout)?.UpdateOpacityChange(); } private static void PositionChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) diff --git a/src/MahApps.Metro/Controls/MetroWindow.cs b/src/MahApps.Metro/Controls/MetroWindow.cs index e142bf5402..15a08dd99a 100644 --- a/src/MahApps.Metro/Controls/MetroWindow.cs +++ b/src/MahApps.Metro/Controls/MetroWindow.cs @@ -1064,31 +1064,31 @@ private void MetroWindow_SizeChanged(object sender, RoutedEventArgs e) private void ThemeManagerOnIsThemeChanged(object sender, ThemeChangedEventArgs e) { - if (e.NewTheme != null) - { - var flyouts = this.Flyouts.GetFlyouts().ToList(); - // since we disabled the ThemeManager OnThemeChanged part, we must change all children flyouts too - // e.g if the FlyoutsControl is hosted in a UserControl - var allChildFlyouts = (this.Content as DependencyObject).FindChildren(true).ToList(); - if (allChildFlyouts.Any()) + this.Invoke(() => { - flyouts.AddRange(allChildFlyouts.SelectMany(flyoutsControl => flyoutsControl.GetFlyouts())); - } + var flyouts = this.Flyouts.GetFlyouts().ToList(); + // since we disabled the ThemeManager OnThemeChanged part, we must change all children flyouts too + // e.g if the FlyoutsControl is hosted in a UserControl + var allChildFlyouts = (this.Content as DependencyObject).FindChildren(true).ToList(); + if (allChildFlyouts.Any()) + { + flyouts.AddRange(allChildFlyouts.SelectMany(flyoutsControl => flyoutsControl.GetFlyouts())); + } - if (!flyouts.Any()) - { - // we must update the window command brushes!!! - this.ResetAllWindowCommandsBrush(); - return; - } + if (!flyouts.Any()) + { + // we must update the window command brushes!!! + this.ResetAllWindowCommandsBrush(); + return; + } - foreach (var flyout in flyouts) - { - flyout.ChangeFlyoutTheme(e.NewTheme); - } - - this.HandleWindowCommandsForFlyouts(flyouts); - } + foreach (var flyout in flyouts) + { + flyout.ChangeFlyoutTheme(e.NewTheme); + } + + this.HandleWindowCommandsForFlyouts(flyouts); + }); } private void FlyoutsPreviewMouseDown(object sender, MouseButtonEventArgs e) From f2c9f3199d329af0eb7e7c7e46426a7c3c77d95d Mon Sep 17 00:00:00 2001 From: punker76 Date: Tue, 7 Jul 2020 12:04:29 +0200 Subject: [PATCH 2/2] Set GitVersion to v5.3.7 --- build.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cake b/build.cake index c08ed25079..afe5a75949 100644 --- a/build.cake +++ b/build.cake @@ -6,7 +6,7 @@ #tool "dotnet:?package=NuGetKeyVaultSignTool&version=1.2.18" #tool "dotnet:?package=AzureSignTool&version=2.0.17" -#tool GitVersion.CommandLine&version=5.0.1 +#tool GitVersion.CommandLine&version=5.3.7 #tool gitreleasemanager #tool xunit.runner.console #tool vswhere