From 7d696903da912e60db1206402ffea30f934c87d3 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Wed, 26 Jul 2023 11:12:27 +0200 Subject: [PATCH 1/5] fix: Ensure ThemeResource bindings are properly updated when style is applied --- src/Uno.UI/UI/Xaml/Style/Style.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/Style/Style.cs b/src/Uno.UI/UI/Xaml/Style/Style.cs index b7a91cb5b436..d691f9621d99 100644 --- a/src/Uno.UI/UI/Xaml/Style/Style.cs +++ b/src/Uno.UI/UI/Xaml/Style/Style.cs @@ -73,7 +73,7 @@ internal void ApplyTo(DependencyObject o, DependencyPropertyValuePrecedences pre return; } - var localPrecedenceDisposable = DependencyObjectExtensions.OverrideLocalPrecedence(o, precedence); + IDisposable? localPrecedenceDisposable = DependencyObjectExtensions.OverrideLocalPrecedence(o, precedence); EnsureSetterMap(); @@ -91,15 +91,17 @@ internal void ApplyTo(DependencyObject o, DependencyPropertyValuePrecedences pre } } + localPrecedenceDisposable?.Dispose(); + // Check tree for resource binding values, since some Setters may have set ThemeResource-backed values - (o as IDependencyObjectStoreProvider)!.Store.UpdateResourceBindings(ResourceUpdateReason.StaticResourceLoading); + (o as IDependencyObjectStoreProvider)!.Store.UpdateResourceBindings(ResourceUpdateReason.ResolvedOnLoading); } #if !HAS_EXPENSIVE_TRYFINALLY finally #endif { - ResourceResolver.PopScope(); localPrecedenceDisposable?.Dispose(); + ResourceResolver.PopScope(); } } From e51e1207097c6e8eaafa94274826e64f0253b0a0 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Wed, 26 Jul 2023 11:49:29 +0200 Subject: [PATCH 2/5] test: ThemeResource style switch --- .../When_ThemeResource_Style_Switch_Page.xaml | 28 +++++++++++++++++++ ...en_ThemeResource_Style_Switch_Page.xaml.cs | 26 +++++++++++++++++ .../Windows_UI_Xaml/Given_ThemeResource.cs | 23 +++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_ThemeResource_Style_Switch_Page.xaml create mode 100644 src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_ThemeResource_Style_Switch_Page.xaml.cs diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_ThemeResource_Style_Switch_Page.xaml b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_ThemeResource_Style_Switch_Page.xaml new file mode 100644 index 000000000000..34aae283f42d --- /dev/null +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_ThemeResource_Style_Switch_Page.xaml @@ -0,0 +1,28 @@ + + + + + + + + + + + + +