From c86a07a1ff699b7690a7e8b1f981da6caca2b58c Mon Sep 17 00:00:00 2001 From: Dustin Wojciechowski Date: Tue, 7 Feb 2023 21:00:07 -0800 Subject: [PATCH 01/15] Moved initialization of radioButtonThemeColor and radioButtonCheckMarkThemeColor into BuildDefaultTemplate() in order for correct colors to display when MacOS/iOS is in Dark Mode. --- src/Controls/src/Core/RadioButton.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Controls/src/Core/RadioButton.cs b/src/Controls/src/Core/RadioButton.cs index 372d83b34138..3cba3f1b4a0c 100644 --- a/src/Controls/src/Core/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton.cs @@ -31,8 +31,6 @@ public partial class RadioButton : TemplatedView, IElementConfiguration> _platformConfigurationRegistry; @@ -466,6 +464,9 @@ static View BuildDefaultTemplate() Padding = 6 }; + Brush radioButtonCheckMarkThemeColor = ResolveThemeColor("RadioButtonCheckMarkThemeColor"); + Brush radioButtonThemeColor = ResolveThemeColor("RadioButtonThemeColor"); + BindToTemplatedParent(frame, BackgroundColorProperty, Microsoft.Maui.Controls.Frame.BorderColorProperty, HorizontalOptionsProperty, MarginProperty, OpacityProperty, RotationProperty, ScaleProperty, ScaleXProperty, ScaleYProperty, TranslationYProperty, TranslationXProperty, VerticalOptionsProperty); @@ -491,13 +492,13 @@ static View BuildDefaultTemplate() HeightRequest = 21, WidthRequest = 21, StrokeThickness = 2, - Stroke = RadioButtonThemeColor, + Stroke = radioButtonThemeColor, InputTransparent = true }; var checkMark = new Ellipse { - Fill = RadioButtonCheckMarkThemeColor, + Fill = radioButtonCheckMarkThemeColor, Aspect = Stretch.Uniform, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, @@ -542,12 +543,12 @@ static View BuildDefaultTemplate() VisualState checkedVisualState = new VisualState() { Name = CheckedVisualState }; checkedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 1 }); - checkedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = RadioButtonCheckMarkThemeColor }); + checkedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = radioButtonCheckMarkThemeColor }); checkedStates.States.Add(checkedVisualState); VisualState uncheckedVisualState = new VisualState() { Name = UncheckedVisualState }; uncheckedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 0 }); - uncheckedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = RadioButtonThemeColor }); + uncheckedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = radioButtonThemeColor }); checkedStates.States.Add(uncheckedVisualState); visualStateGroups.Add(checkedStates); From dbbc6dd3284e9cf177b8006c82aed6b391de9012 Mon Sep 17 00:00:00 2001 From: Dustin Wojciechowski Date: Wed, 8 Feb 2023 15:15:28 -0800 Subject: [PATCH 02/15] Added test CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes --- .../tests/Core.UnitTests/AppThemeTests.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Controls/tests/Core.UnitTests/AppThemeTests.cs b/src/Controls/tests/Core.UnitTests/AppThemeTests.cs index 116012673794..7e3ddde230dd 100644 --- a/src/Controls/tests/Core.UnitTests/AppThemeTests.cs +++ b/src/Controls/tests/Core.UnitTests/AppThemeTests.cs @@ -195,6 +195,36 @@ public void ThemeBindingRemovedOnOneTimeBindablePropertyWhenPropertySet() Assert.Equal(Colors.Pink, shell.FlyoutBackgroundColor); } + void validateRadioButtonColors(RadioButton button, SolidColorBrush desiredBrush) + { + if (button.Children[0] is Frame frame) + { + if (frame.Children[0] is Grid grid) + { + if (grid.Children[0] is Shapes.Ellipse outerEllipse) + { + Assert.Equal(desiredBrush, outerEllipse.Stroke); + } + if (grid.Children[1] is Shapes.Ellipse innerEllipse) + { + Assert.Equal(desiredBrush, innerEllipse.Fill); + } + } + } + } + + [Fact] + public void CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes() + { + validateRadioButtonColors( + new RadioButton() { ControlTemplate = RadioButton.DefaultTemplate }, + Brush.Black); + SetAppTheme(AppTheme.Dark); + validateRadioButtonColors( + new RadioButton() { ControlTemplate = RadioButton.DefaultTemplate }, + Brush.White); + } + [Fact] public void NullApplicationCurrentFallsBackToEssentials() { From 9fbf5977bd105b8883611d49ccecb846792badf0 Mon Sep 17 00:00:00 2001 From: Dustin Wojciechowski Date: Thu, 9 Feb 2023 08:56:44 -0800 Subject: [PATCH 03/15] Added RadioButton changes to Tizen version. Redid test to use casting. --- .../RadioButton/RadioButton.Tizen.cs | 11 ++++++---- .../tests/Core.UnitTests/AppThemeTests.cs | 21 +++++++------------ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs index 8e90cf9dced7..045a7a5be216 100644 --- a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs +++ b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs @@ -28,6 +28,9 @@ static View BuildTizenDefaultTemplate() Padding = 6 }; + Brush radioButtonCheckMarkThemeColor = ResolveThemeColor("RadioButtonCheckMarkThemeColor"); + Brush radioButtonThemeColor = ResolveThemeColor("RadioButtonThemeColor"); + BindToTemplatedParent(frame, BackgroundColorProperty, Controls.Frame.BorderColorProperty, Controls.Frame.CornerRadiusProperty, HorizontalOptionsProperty, MarginProperty, OpacityProperty, RotationProperty, ScaleProperty, ScaleXProperty, ScaleYProperty, TranslationYProperty, TranslationXProperty, VerticalOptionsProperty); @@ -54,13 +57,13 @@ static View BuildTizenDefaultTemplate() HeightRequest = 21, WidthRequest = 21, StrokeThickness = 2, - Stroke = RadioButtonThemeColor, + Stroke = radioButtonThemeColor, InputTransparent = true }; var checkMark = new Ellipse { - Fill = RadioButtonCheckMarkThemeColor, + Fill = radioButtonCheckMarkThemeColor, Aspect = Stretch.Uniform, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, @@ -104,12 +107,12 @@ static View BuildTizenDefaultTemplate() VisualState checkedVisualState = new VisualState() { Name = CheckedVisualState }; checkedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 1 }); - checkedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = RadioButtonCheckMarkThemeColor }); + checkedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = radioButtonCheckMarkThemeColor }); checkedStates.States.Add(checkedVisualState); VisualState uncheckedVisualState = new VisualState() { Name = UncheckedVisualState }; uncheckedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 0 }); - uncheckedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = RadioButtonThemeColor }); + uncheckedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = radioButtonThemeColor }); checkedStates.States.Add(uncheckedVisualState); visualStateGroups.Add(checkedStates); diff --git a/src/Controls/tests/Core.UnitTests/AppThemeTests.cs b/src/Controls/tests/Core.UnitTests/AppThemeTests.cs index 7e3ddde230dd..114a41e37f00 100644 --- a/src/Controls/tests/Core.UnitTests/AppThemeTests.cs +++ b/src/Controls/tests/Core.UnitTests/AppThemeTests.cs @@ -197,20 +197,13 @@ public void ThemeBindingRemovedOnOneTimeBindablePropertyWhenPropertySet() void validateRadioButtonColors(RadioButton button, SolidColorBrush desiredBrush) { - if (button.Children[0] is Frame frame) - { - if (frame.Children[0] is Grid grid) - { - if (grid.Children[0] is Shapes.Ellipse outerEllipse) - { - Assert.Equal(desiredBrush, outerEllipse.Stroke); - } - if (grid.Children[1] is Shapes.Ellipse innerEllipse) - { - Assert.Equal(desiredBrush, innerEllipse.Fill); - } - } - } + var frame = (Frame)button.Children[0]; + var grid = (Grid)frame.Children[0]; + var outerEllipse = (Shapes.Ellipse)grid.Children[0]; + var innerEllipse = (Shapes.Ellipse)grid.Children[1]; + + Assert.Equal(desiredBrush, outerEllipse.Stroke); + Assert.Equal(desiredBrush, innerEllipse.Fill); } [Fact] From 1144d01c68686dc4c9fae085b0c733376628cc5b Mon Sep 17 00:00:00 2001 From: Dustin Wojciechowski Date: Thu, 9 Feb 2023 10:03:42 -0800 Subject: [PATCH 04/15] Added AppThemeBinding for light/dark modes to VisualStateGroups for RadioButton and RadioButton.Tizen --- .../HandlerImpl/RadioButton/RadioButton.Tizen.cs | 16 ++++++++++++++-- src/Controls/src/Core/RadioButton.cs | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs index 045a7a5be216..94fd4aa3874c 100644 --- a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs +++ b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs @@ -107,12 +107,24 @@ static View BuildTizenDefaultTemplate() VisualState checkedVisualState = new VisualState() { Name = CheckedVisualState }; checkedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 1 }); - checkedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = radioButtonCheckMarkThemeColor }); + checkedVisualState.Setters.Add( + new Setter() + { + Property = Shape.StrokeProperty, + TargetName = UncheckedButton, + Value = new AppThemeBinding() { Light = Colors.Black.MultiplyAlpha(0.1f), Dark = Colors.White.MultiplyAlpha(0.1f) } + }); checkedStates.States.Add(checkedVisualState); VisualState uncheckedVisualState = new VisualState() { Name = UncheckedVisualState }; uncheckedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 0 }); - uncheckedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = radioButtonThemeColor }); + uncheckedVisualState.Setters.Add( + new Setter() + { + Property = Shape.StrokeProperty, + TargetName = UncheckedButton, + Value = new AppThemeBinding() { Light = Colors.Black, Dark = Colors.White } + }); checkedStates.States.Add(uncheckedVisualState); visualStateGroups.Add(checkedStates); diff --git a/src/Controls/src/Core/RadioButton.cs b/src/Controls/src/Core/RadioButton.cs index 3cba3f1b4a0c..004c6aa69f99 100644 --- a/src/Controls/src/Core/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton.cs @@ -543,12 +543,22 @@ static View BuildDefaultTemplate() VisualState checkedVisualState = new VisualState() { Name = CheckedVisualState }; checkedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 1 }); - checkedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = radioButtonCheckMarkThemeColor }); + checkedVisualState.Setters.Add( + new Setter() { + Property = Shape.StrokeProperty, + TargetName = UncheckedButton, + Value = new AppThemeBinding() { Light = Colors.Black.MultiplyAlpha(0.1f), Dark = Colors.White.MultiplyAlpha(0.1f) } + }); checkedStates.States.Add(checkedVisualState); VisualState uncheckedVisualState = new VisualState() { Name = UncheckedVisualState }; uncheckedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 0 }); - uncheckedVisualState.Setters.Add(new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = radioButtonThemeColor }); + uncheckedVisualState.Setters.Add( + new Setter() { + Property = Shape.StrokeProperty, + TargetName = UncheckedButton, + Value = new AppThemeBinding() { Light = Colors.Black, Dark = Colors.White } + }); checkedStates.States.Add(uncheckedVisualState); visualStateGroups.Add(checkedStates); From ec43e047aece8c245dea4a91def93b2406c321a9 Mon Sep 17 00:00:00 2001 From: Dustin Wojciechowski Date: Thu, 9 Feb 2023 12:52:22 -0800 Subject: [PATCH 05/15] Fix for Graphics.Colors in RadioButton.Tizen --- .../src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs index 94fd4aa3874c..98260a851a7c 100644 --- a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs +++ b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs @@ -1,6 +1,7 @@ #nullable disable using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Controls.Shapes; +using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls { From 6523d0e6fc3e7e246d6eec08811f73f9947cc917 Mon Sep 17 00:00:00 2001 From: GitHub Actions Autoformatter Date: Mon, 6 Mar 2023 21:23:53 +0000 Subject: [PATCH 06/15] Auto-format source code --- src/Controls/src/Core/RadioButton.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Controls/src/Core/RadioButton.cs b/src/Controls/src/Core/RadioButton.cs index e9113b0ea478..93d7ba216767 100644 --- a/src/Controls/src/Core/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton.cs @@ -557,7 +557,8 @@ static View BuildDefaultTemplate() VisualState checkedVisualState = new VisualState() { Name = CheckedVisualState }; checkedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 1 }); checkedVisualState.Setters.Add( - new Setter() { + new Setter() + { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = new AppThemeBinding() { Light = Colors.Black.MultiplyAlpha(0.1f), Dark = Colors.White.MultiplyAlpha(0.1f) } @@ -567,7 +568,8 @@ static View BuildDefaultTemplate() VisualState uncheckedVisualState = new VisualState() { Name = UncheckedVisualState }; uncheckedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 0 }); uncheckedVisualState.Setters.Add( - new Setter() { + new Setter() + { Property = Shape.StrokeProperty, TargetName = UncheckedButton, Value = new AppThemeBinding() { Light = Colors.Black, Dark = Colors.White } From 44ad5e27e731a5cd42534a0f3f163172917e31ca Mon Sep 17 00:00:00 2001 From: Dustin Wojciechowski Date: Tue, 7 Mar 2023 12:49:02 -0800 Subject: [PATCH 07/15] Addressed PR comments. Made changes to Tizen version as well. --- .../RadioButton/RadioButton.Tizen.cs | 65 ++++++++++++++++-- src/Controls/src/Core/RadioButton.cs | 67 +++++++++++++++++-- 2 files changed, 118 insertions(+), 14 deletions(-) diff --git a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs index 98260a851a7c..8a5f2c3cb4cb 100644 --- a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs +++ b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs @@ -29,9 +29,6 @@ static View BuildTizenDefaultTemplate() Padding = 6 }; - Brush radioButtonCheckMarkThemeColor = ResolveThemeColor("RadioButtonCheckMarkThemeColor"); - Brush radioButtonThemeColor = ResolveThemeColor("RadioButtonThemeColor"); - BindToTemplatedParent(frame, BackgroundColorProperty, Controls.Frame.BorderColorProperty, Controls.Frame.CornerRadiusProperty, HorizontalOptionsProperty, MarginProperty, OpacityProperty, RotationProperty, ScaleProperty, ScaleXProperty, ScaleYProperty, TranslationYProperty, TranslationXProperty, VerticalOptionsProperty); @@ -58,13 +55,11 @@ static View BuildTizenDefaultTemplate() HeightRequest = 21, WidthRequest = 21, StrokeThickness = 2, - Stroke = radioButtonThemeColor, InputTransparent = true }; var checkMark = new Ellipse { - Fill = radioButtonCheckMarkThemeColor, Aspect = Stretch.Uniform, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, @@ -80,6 +75,55 @@ static View BuildTizenDefaultTemplate() VerticalOptions = LayoutOptions.Center }; + object outerEllipseVisualStateLight; + object outerEllipseVisualStateDark; + object checkMarkVisualStateLight; + object checkMarkVisualStateDark; + + // First, Light/Dark App themes for outer ellipse, then for the check mark. + // Then check for older themecolor. + // If nothing set, use the defaults for light/dark mode. + if (Application.Current.TryGetResource("RadioButtonOuterEllipseStrokeLight", out var outerLight) && + Application.Current.TryGetResource("RadioButtonOuterEllipseStrokeDark", out var outerDark)) + { + normalEllipse.SetAppTheme(Ellipse.StrokeProperty, outerLight, outerDark); + outerEllipseVisualStateLight = outerLight; + outerEllipseVisualStateDark = outerDark; + } + else if (Application.Current.TryGetResource("RadioButtonThemeColor", out var themeColor)) + { + normalEllipse.SetDynamicResource(Ellipse.StrokeProperty, "RadioButtonThemeColor"); + outerEllipseVisualStateLight = outerEllipseVisualStateDark = themeColor; + } + else + { + normalEllipse.SetAppTheme(Ellipse.StrokeProperty, SolidColorBrush.Black, SolidColorBrush.White); + outerEllipseVisualStateLight = SolidColorBrush.Black; + outerEllipseVisualStateDark = SolidColorBrush.White; + } + + if (Application.Current.TryGetResource("RadioButtonCheckGlyphStrokeLight", out var checkLight) && + Application.Current.TryGetResource("RadioButtonCheckGlyphStrokeDark", out var checkDark)) + { + checkMark.SetAppTheme(Ellipse.StrokeProperty, checkLight, checkDark); + checkMark.Fill = (Brush)(Application.Current?.RequestedTheme == AppTheme.Dark ? checkDark : checkLight); + checkMarkVisualStateLight = checkLight; + checkMarkVisualStateDark = checkDark; + } + else if (Application.Current.TryGetResource("RadioButtonCheckMarkThemeColor", out var themeColor)) + { + checkMark.SetDynamicResource(Ellipse.StrokeProperty, "RadioButtonCheckMarkThemeColor"); + checkMark.Fill = (Brush)themeColor; + checkMarkVisualStateLight = checkMarkVisualStateDark = themeColor; + } + else + { + checkMark.SetAppTheme(Ellipse.StrokeProperty, SolidColorBrush.Black, SolidColorBrush.White); + checkMark.Fill = (Application.Current?.RequestedTheme == AppTheme.Dark) ? SolidColorBrush.White : SolidColorBrush.Black; + checkMarkVisualStateLight = SolidColorBrush.Black; + checkMarkVisualStateDark = SolidColorBrush.White; + } + contentPresenter.SetBinding(BackgroundColorProperty, new Binding(BackgroundColorProperty.PropertyName, source: RelativeBindingSource.TemplatedParent)); @@ -113,7 +157,14 @@ static View BuildTizenDefaultTemplate() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, - Value = new AppThemeBinding() { Light = Colors.Black.MultiplyAlpha(0.1f), Dark = Colors.White.MultiplyAlpha(0.1f) } + Value = new AppThemeBinding() { Light = outerEllipseVisualStateLight, Dark = outerEllipseVisualStateDark } + }); + checkedVisualState.Setters.Add( + new Setter() + { + Property = Shape.StrokeProperty, + TargetName = CheckedIndicator, + Value = new AppThemeBinding() { Light = checkMarkVisualStateLight, Dark = checkMarkVisualStateDark } }); checkedStates.States.Add(checkedVisualState); @@ -124,7 +175,7 @@ static View BuildTizenDefaultTemplate() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, - Value = new AppThemeBinding() { Light = Colors.Black, Dark = Colors.White } + Value = new AppThemeBinding() { Light = outerEllipseVisualStateLight, Dark = outerEllipseVisualStateDark } }); checkedStates.States.Add(uncheckedVisualState); diff --git a/src/Controls/src/Core/RadioButton.cs b/src/Controls/src/Core/RadioButton.cs index 93d7ba216767..eed178894f6a 100644 --- a/src/Controls/src/Core/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton.cs @@ -463,9 +463,6 @@ static View BuildDefaultTemplate() Padding = 6 }; - Brush radioButtonCheckMarkThemeColor = ResolveThemeColor("RadioButtonCheckMarkThemeColor"); - Brush radioButtonThemeColor = ResolveThemeColor("RadioButtonThemeColor"); - BindToTemplatedParent(border, BackgroundColorProperty, HorizontalOptionsProperty, MarginProperty, OpacityProperty, RotationProperty, ScaleProperty, ScaleXProperty, ScaleYProperty, TranslationYProperty, TranslationXProperty, VerticalOptionsProperty); @@ -505,13 +502,11 @@ static View BuildDefaultTemplate() HeightRequest = 21, WidthRequest = 21, StrokeThickness = 2, - Stroke = radioButtonThemeColor, InputTransparent = true }; var checkMark = new Ellipse { - Fill = radioButtonCheckMarkThemeColor, Aspect = Stretch.Uniform, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, @@ -527,6 +522,55 @@ static View BuildDefaultTemplate() VerticalOptions = LayoutOptions.Fill }; + object outerEllipseVisualStateLight; + object outerEllipseVisualStateDark; + object checkMarkVisualStateLight; + object checkMarkVisualStateDark; + + // First, Light/Dark App themes for outer ellipse, then for the check mark. + // Then check for older themecolor. + // If nothing set, use the defaults for light/dark mode. + if (Application.Current.TryGetResource("RadioButtonOuterEllipseStrokeLight", out var outerLight) && + Application.Current.TryGetResource("RadioButtonOuterEllipseStrokeDark", out var outerDark)) + { + normalEllipse.SetAppTheme(Ellipse.StrokeProperty, outerLight, outerDark); + outerEllipseVisualStateLight = outerLight; + outerEllipseVisualStateDark = outerDark; + } + else if (Application.Current.TryGetResource("RadioButtonThemeColor", out var themeColor)) + { + normalEllipse.SetDynamicResource(Ellipse.StrokeProperty, "RadioButtonThemeColor"); + outerEllipseVisualStateLight = outerEllipseVisualStateDark = themeColor; + } + else + { + normalEllipse.SetAppTheme(Ellipse.StrokeProperty, SolidColorBrush.Black, SolidColorBrush.White); + outerEllipseVisualStateLight = SolidColorBrush.Black; + outerEllipseVisualStateDark = SolidColorBrush.White; + } + + if (Application.Current.TryGetResource("RadioButtonCheckGlyphStrokeLight", out var checkLight) && + Application.Current.TryGetResource("RadioButtonCheckGlyphStrokeDark", out var checkDark)) + { + checkMark.SetAppTheme(Ellipse.StrokeProperty, checkLight, checkDark); + checkMark.Fill = (Brush)(Application.Current?.RequestedTheme == AppTheme.Dark ? checkDark : checkLight); + checkMarkVisualStateLight = checkLight; + checkMarkVisualStateDark = checkDark; + } + else if (Application.Current.TryGetResource("RadioButtonCheckMarkThemeColor", out var themeColor)) + { + checkMark.SetDynamicResource(Ellipse.StrokeProperty, "RadioButtonCheckMarkThemeColor"); + checkMark.Fill = (Brush)themeColor; + checkMarkVisualStateLight = checkMarkVisualStateDark = themeColor; + } + else + { + checkMark.SetAppTheme(Ellipse.StrokeProperty, SolidColorBrush.Black, SolidColorBrush.White); + checkMark.Fill = (Application.Current?.RequestedTheme == AppTheme.Dark) ? SolidColorBrush.White : SolidColorBrush.Black; + checkMarkVisualStateLight = SolidColorBrush.Black; + checkMarkVisualStateDark = SolidColorBrush.White; + } + contentPresenter.SetBinding(MarginProperty, new Binding("Padding", source: RelativeBindingSource.TemplatedParent)); contentPresenter.SetBinding(BackgroundColorProperty, new Binding(BackgroundColorProperty.PropertyName, source: RelativeBindingSource.TemplatedParent)); @@ -561,19 +605,28 @@ static View BuildDefaultTemplate() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, - Value = new AppThemeBinding() { Light = Colors.Black.MultiplyAlpha(0.1f), Dark = Colors.White.MultiplyAlpha(0.1f) } + Value = new AppThemeBinding() { Light = outerEllipseVisualStateLight, Dark = outerEllipseVisualStateDark } + }); + checkedVisualState.Setters.Add( + new Setter() + { + Property = Shape.StrokeProperty, + TargetName = CheckedIndicator, + Value = new AppThemeBinding() { Light = checkMarkVisualStateLight, Dark = checkMarkVisualStateDark } }); checkedStates.States.Add(checkedVisualState); VisualState uncheckedVisualState = new VisualState() { Name = UncheckedVisualState }; uncheckedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 0 }); + uncheckedVisualState.Setters.Add( new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, - Value = new AppThemeBinding() { Light = Colors.Black, Dark = Colors.White } + Value = new AppThemeBinding() { Light = outerEllipseVisualStateLight, Dark = outerEllipseVisualStateDark } }); + checkedStates.States.Add(uncheckedVisualState); visualStateGroups.Add(checkedStates); From bd08452680ec6cca00bce9c636f81498a8aa755e Mon Sep 17 00:00:00 2001 From: GitHub Actions Autoformatter Date: Tue, 7 Mar 2023 20:53:41 +0000 Subject: [PATCH 08/15] Auto-format source code --- src/Controls/src/Core/RadioButton.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controls/src/Core/RadioButton.cs b/src/Controls/src/Core/RadioButton.cs index eed178894f6a..864d05d5ea2c 100644 --- a/src/Controls/src/Core/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton.cs @@ -618,7 +618,7 @@ static View BuildDefaultTemplate() VisualState uncheckedVisualState = new VisualState() { Name = UncheckedVisualState }; uncheckedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 0 }); - + uncheckedVisualState.Setters.Add( new Setter() { @@ -626,7 +626,7 @@ static View BuildDefaultTemplate() TargetName = UncheckedButton, Value = new AppThemeBinding() { Light = outerEllipseVisualStateLight, Dark = outerEllipseVisualStateDark } }); - + checkedStates.States.Add(uncheckedVisualState); visualStateGroups.Add(checkedStates); From 29b10296b55ddb54c2fab3a4b1c36fb029bb8bf7 Mon Sep 17 00:00:00 2001 From: Dustin Wojciechowski Date: Tue, 7 Mar 2023 13:20:31 -0800 Subject: [PATCH 09/15] Made strings constant --- .../RadioButton/RadioButton.Tizen.cs | 16 +++++------ src/Controls/src/Core/RadioButton.cs | 27 +++++++++++++------ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs index 8a5f2c3cb4cb..e3bf4dacdbda 100644 --- a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs +++ b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs @@ -83,16 +83,16 @@ static View BuildTizenDefaultTemplate() // First, Light/Dark App themes for outer ellipse, then for the check mark. // Then check for older themecolor. // If nothing set, use the defaults for light/dark mode. - if (Application.Current.TryGetResource("RadioButtonOuterEllipseStrokeLight", out var outerLight) && - Application.Current.TryGetResource("RadioButtonOuterEllipseStrokeDark", out var outerDark)) + if (Application.Current.TryGetResource(RadioButtonOuterEllipseStrokeLight, out var outerLight) && + Application.Current.TryGetResource(RadioButtonOuterEllipseStrokeDark, out var outerDark)) { normalEllipse.SetAppTheme(Ellipse.StrokeProperty, outerLight, outerDark); outerEllipseVisualStateLight = outerLight; outerEllipseVisualStateDark = outerDark; } - else if (Application.Current.TryGetResource("RadioButtonThemeColor", out var themeColor)) + else if (Application.Current.TryGetResource(RadioButtonThemeColor, out var themeColor)) { - normalEllipse.SetDynamicResource(Ellipse.StrokeProperty, "RadioButtonThemeColor"); + normalEllipse.SetDynamicResource(Ellipse.StrokeProperty, RadioButtonThemeColor); outerEllipseVisualStateLight = outerEllipseVisualStateDark = themeColor; } else @@ -102,17 +102,17 @@ static View BuildTizenDefaultTemplate() outerEllipseVisualStateDark = SolidColorBrush.White; } - if (Application.Current.TryGetResource("RadioButtonCheckGlyphStrokeLight", out var checkLight) && - Application.Current.TryGetResource("RadioButtonCheckGlyphStrokeDark", out var checkDark)) + if (Application.Current.TryGetResource(RadioButtonCheckGlyphStrokeLight, out var checkLight) && + Application.Current.TryGetResource(RadioButtonCheckGlyphStrokeDark, out var checkDark)) { checkMark.SetAppTheme(Ellipse.StrokeProperty, checkLight, checkDark); checkMark.Fill = (Brush)(Application.Current?.RequestedTheme == AppTheme.Dark ? checkDark : checkLight); checkMarkVisualStateLight = checkLight; checkMarkVisualStateDark = checkDark; } - else if (Application.Current.TryGetResource("RadioButtonCheckMarkThemeColor", out var themeColor)) + else if (Application.Current.TryGetResource(RadioButtonCheckMarkThemeColor, out var themeColor)) { - checkMark.SetDynamicResource(Ellipse.StrokeProperty, "RadioButtonCheckMarkThemeColor"); + checkMark.SetDynamicResource(Ellipse.StrokeProperty, RadioButtonCheckMarkThemeColor); checkMark.Fill = (Brush)themeColor; checkMarkVisualStateLight = checkMarkVisualStateDark = themeColor; } diff --git a/src/Controls/src/Core/RadioButton.cs b/src/Controls/src/Core/RadioButton.cs index 864d05d5ea2c..000cf80a8d1a 100644 --- a/src/Controls/src/Core/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton.cs @@ -27,6 +27,17 @@ public partial class RadioButton : TemplatedView, IElementConfiguration Date: Wed, 8 Mar 2023 14:56:17 -0800 Subject: [PATCH 10/15] Created new EllipseExtensions class, added methods for TrySetAppTheme, TrySetDynamicTheme, TrySetFill. Updated RadioButton code to use those methods. Removed old ResolveThemeColor method. --- .../net-android/PublicAPI.Unshipped.txt | 4 + .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 4 + .../net-maccatalyst/PublicAPI.Unshipped.txt | 4 + .../PublicAPI/net/PublicAPI.Unshipped.txt | 4 + .../netstandard/PublicAPI.Unshipped.txt | 4 + src/Controls/src/Core/RadioButton.cs | 103 +++++++----------- .../src/Core/Shapes/EllipseExtensions.cs | 69 ++++++++++++ 7 files changed, 131 insertions(+), 61 deletions(-) create mode 100644 src/Controls/src/Core/Shapes/EllipseExtensions.cs diff --git a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt index b58af6e02992..dcfe6219375b 100644 --- a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt @@ -4,6 +4,7 @@ Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.FrameRenderer(Andro Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.FrameRenderer(Android.Content.Context! context, Microsoft.Maui.IPropertyMapper! mapper, Microsoft.Maui.CommandMapper! commandMapper) -> void Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool +Microsoft.Maui.Controls.Shapes.EllipseExtensions Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool override Microsoft.Maui.Controls.LayoutOptions.GetHashCode() -> int override Microsoft.Maui.Controls.Region.GetHashCode() -> int @@ -26,6 +27,9 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetFillFromAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight) -> void ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt index ceefe7046f1b..082baa30c75c 100644 --- a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -2,6 +2,7 @@ *REMOVED*override Microsoft.Maui.Controls.RefreshView.MeasureOverride(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool +Microsoft.Maui.Controls.Shapes.EllipseExtensions Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool override Microsoft.Maui.Controls.LayoutOptions.GetHashCode() -> int override Microsoft.Maui.Controls.Platform.Compatibility.ShellPageRendererTracker.TitleViewContainer.LayoutSubviews() -> void @@ -36,6 +37,9 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~Microsoft.Maui.Controls.WebView.UserAgent.set -> void ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetFillFromAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight) -> void ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 29fd1fc277ff..3df77b0881a4 100644 --- a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -2,6 +2,7 @@ *REMOVED*override Microsoft.Maui.Controls.RefreshView.MeasureOverride(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool +Microsoft.Maui.Controls.Shapes.EllipseExtensions Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool override Microsoft.Maui.Controls.LayoutOptions.GetHashCode() -> int override Microsoft.Maui.Controls.Platform.Compatibility.ShellPageRendererTracker.TitleViewContainer.LayoutSubviews() -> void @@ -36,6 +37,9 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~Microsoft.Maui.Controls.WebView.UserAgent.set -> void ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetFillFromAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight) -> void ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt index ce1ce9c01052..e2dd705d7f85 100644 --- a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt @@ -2,6 +2,7 @@ *REMOVED*override Microsoft.Maui.Controls.RefreshView.MeasureOverride(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool +Microsoft.Maui.Controls.Shapes.EllipseExtensions Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool override Microsoft.Maui.Controls.LayoutOptions.GetHashCode() -> int override Microsoft.Maui.Controls.Region.GetHashCode() -> int @@ -23,6 +24,9 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetFillFromAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight) -> void ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt index 3c4068b91838..836c37bd4c0c 100644 --- a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt @@ -2,6 +2,7 @@ *REMOVED*override Microsoft.Maui.Controls.RefreshView.MeasureOverride(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool +Microsoft.Maui.Controls.Shapes.EllipseExtensions Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool override Microsoft.Maui.Controls.LayoutOptions.GetHashCode() -> int override Microsoft.Maui.Controls.Region.GetHashCode() -> int @@ -31,6 +32,9 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool +~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetFillFromAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight) -> void ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/RadioButton.cs b/src/Controls/src/Core/RadioButton.cs index 000cf80a8d1a..180eb99aea29 100644 --- a/src/Controls/src/Core/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton.cs @@ -32,6 +32,8 @@ public partial class RadioButton : TemplatedView, IElementConfiguration Date: Thu, 9 Mar 2023 12:15:09 -0800 Subject: [PATCH 11/15] Removed EllipseExtensions class and updated unshipped api files --- .../net-android/PublicAPI.Unshipped.txt | 4 -- .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 4 -- .../net-maccatalyst/PublicAPI.Unshipped.txt | 4 -- .../PublicAPI/net/PublicAPI.Unshipped.txt | 4 -- .../netstandard/PublicAPI.Unshipped.txt | 4 -- .../src/Core/Shapes/EllipseExtensions.cs | 69 ------------------- 6 files changed, 89 deletions(-) delete mode 100644 src/Controls/src/Core/Shapes/EllipseExtensions.cs diff --git a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt index dcfe6219375b..b58af6e02992 100644 --- a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt @@ -4,7 +4,6 @@ Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.FrameRenderer(Andro Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.FrameRenderer(Android.Content.Context! context, Microsoft.Maui.IPropertyMapper! mapper, Microsoft.Maui.CommandMapper! commandMapper) -> void Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool -Microsoft.Maui.Controls.Shapes.EllipseExtensions Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool override Microsoft.Maui.Controls.LayoutOptions.GetHashCode() -> int override Microsoft.Maui.Controls.Region.GetHashCode() -> int @@ -27,9 +26,6 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetFillFromAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight) -> void ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 082baa30c75c..ceefe7046f1b 100644 --- a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -2,7 +2,6 @@ *REMOVED*override Microsoft.Maui.Controls.RefreshView.MeasureOverride(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool -Microsoft.Maui.Controls.Shapes.EllipseExtensions Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool override Microsoft.Maui.Controls.LayoutOptions.GetHashCode() -> int override Microsoft.Maui.Controls.Platform.Compatibility.ShellPageRendererTracker.TitleViewContainer.LayoutSubviews() -> void @@ -37,9 +36,6 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~Microsoft.Maui.Controls.WebView.UserAgent.set -> void ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetFillFromAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight) -> void ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 3df77b0881a4..29fd1fc277ff 100644 --- a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -2,7 +2,6 @@ *REMOVED*override Microsoft.Maui.Controls.RefreshView.MeasureOverride(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool -Microsoft.Maui.Controls.Shapes.EllipseExtensions Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool override Microsoft.Maui.Controls.LayoutOptions.GetHashCode() -> int override Microsoft.Maui.Controls.Platform.Compatibility.ShellPageRendererTracker.TitleViewContainer.LayoutSubviews() -> void @@ -37,9 +36,6 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~Microsoft.Maui.Controls.WebView.UserAgent.set -> void ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetFillFromAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight) -> void ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt index e2dd705d7f85..ce1ce9c01052 100644 --- a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt @@ -2,7 +2,6 @@ *REMOVED*override Microsoft.Maui.Controls.RefreshView.MeasureOverride(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool -Microsoft.Maui.Controls.Shapes.EllipseExtensions Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool override Microsoft.Maui.Controls.LayoutOptions.GetHashCode() -> int override Microsoft.Maui.Controls.Region.GetHashCode() -> int @@ -24,9 +23,6 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetFillFromAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight) -> void ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt index 836c37bd4c0c..3c4068b91838 100644 --- a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt @@ -2,7 +2,6 @@ *REMOVED*override Microsoft.Maui.Controls.RefreshView.MeasureOverride(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool -Microsoft.Maui.Controls.Shapes.EllipseExtensions Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool override Microsoft.Maui.Controls.LayoutOptions.GetHashCode() -> int override Microsoft.Maui.Controls.Region.GetHashCode() -> int @@ -32,9 +31,6 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool -~static Microsoft.Maui.Controls.Shapes.EllipseExtensions.TrySetFillFromAppTheme(this Microsoft.Maui.Controls.Shapes.Ellipse ellipse, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight) -> void ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/Shapes/EllipseExtensions.cs b/src/Controls/src/Core/Shapes/EllipseExtensions.cs deleted file mode 100644 index 94e0fb5dfd8d..000000000000 --- a/src/Controls/src/Core/Shapes/EllipseExtensions.cs +++ /dev/null @@ -1,69 +0,0 @@ -#nullable disable -using Microsoft.Maui.ApplicationModel; - -namespace Microsoft.Maui.Controls.Shapes -{ - public static class EllipseExtensions - { - public static bool TrySetAppTheme( - this Ellipse ellipse, - string lightResourceKey, - string darkResourceKey, - BindableProperty bindableProperty, - Brush defaultDark, - Brush defaultLight, - out object outerLight, - out object outerDark) - { - bool anyValueSet = false; - if (!Application.Current.TryGetResource(lightResourceKey, out outerLight)) - { - anyValueSet = true; - outerLight = defaultLight; - } - if (!Application.Current.TryGetResource(darkResourceKey, out outerDark)) - { - anyValueSet = true; - outerDark = defaultDark; - } - - ellipse.SetAppTheme(bindableProperty, outerLight, outerDark); - return anyValueSet; - } - - public static bool TrySetDynamicThemeColor( - this Ellipse ellipse, - string resourceKey, - BindableProperty bindableProperty, - out object outerColor) - { - if (Application.Current.TryGetResource(resourceKey, out outerColor)) - { - ellipse.SetDynamicResource(bindableProperty, resourceKey); - return true; - } - - return false; - } - - public static void TrySetFillFromAppTheme( - this Ellipse ellipse, - string lightResourceKey, - string darkResourceKey, - Brush defaultDark, - Brush defaultLight) - { - if (!Application.Current.TryGetResource(lightResourceKey, out var outerLight)) - { - outerLight = defaultLight; - } - if (!Application.Current.TryGetResource(darkResourceKey, out var outerDark)) - { - outerDark = defaultDark; - } - - ellipse.Fill = (Brush)(Application.Current?.RequestedTheme == AppTheme.Dark ? outerDark : outerLight); - } - } -} - From 26e86f50a42aa7fd252684990462c227e7a16912 Mon Sep 17 00:00:00 2001 From: Dustin Wojciechowski Date: Thu, 9 Mar 2023 12:40:44 -0800 Subject: [PATCH 12/15] Added TrySetAppTheme and TrySetDynamicTheme to BindableObjectExtensions, updated RadioButton --- .../src/Core/BindableObjectExtensions.cs | 39 +++++++++++++++++++ .../net-android/PublicAPI.Unshipped.txt | 2 + .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 2 + .../net-maccatalyst/PublicAPI.Unshipped.txt | 2 + .../PublicAPI/net/PublicAPI.Unshipped.txt | 2 + .../netstandard/PublicAPI.Unshipped.txt | 2 + src/Controls/src/Core/RadioButton.cs | 19 ++++++--- 7 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/Controls/src/Core/BindableObjectExtensions.cs b/src/Controls/src/Core/BindableObjectExtensions.cs index 8467add5eb09..151fa1aa3147 100644 --- a/src/Controls/src/Core/BindableObjectExtensions.cs +++ b/src/Controls/src/Core/BindableObjectExtensions.cs @@ -70,6 +70,45 @@ public static T GetPropertyIfSet(this BindableObject bindableObject, Bindable return returnIfNotSet; } + public static bool TrySetDynamicThemeColor( + this BindableObject bindableObject, + string resourceKey, + BindableProperty bindableProperty, + out object outerColor) + { + if (Application.Current.TryGetResource(resourceKey, out outerColor)) + { + bindableObject.SetDynamicResource(bindableProperty, resourceKey); + return true; + } + + return false; + } + + public static bool TrySetAppTheme( + this BindableObject self, + string lightResourceKey, + string darkResourceKey, + BindableProperty bindableProperty, + Brush defaultDark, + Brush defaultLight, + out object outerLight, + out object outerDark) + { + if (!Application.Current.TryGetResource(lightResourceKey, out outerLight)) + { + outerLight = defaultLight; + } + + if (!Application.Current.TryGetResource(darkResourceKey, out outerDark)) + { + outerDark = defaultDark; + } + + self.SetAppTheme(bindableProperty, outerLight, outerDark); + return (Brush)outerLight != defaultLight || (Brush)outerDark != defaultDark; + } + public static void SetAppTheme(this BindableObject self, BindableProperty targetProperty, T light, T dark) => self.SetBinding(targetProperty, new AppThemeBinding { Light = light, Dark = dark }); /// diff --git a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt index b58af6e02992..0f628e0b48d5 100644 --- a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt @@ -26,6 +26,8 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool +~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.BindableObject self, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool +~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.BindableObject bindableObject, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt index ceefe7046f1b..86ae82c9f5b2 100644 --- a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -36,6 +36,8 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~Microsoft.Maui.Controls.WebView.UserAgent.set -> void ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool +~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.BindableObject self, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool +~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.BindableObject bindableObject, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 29fd1fc277ff..664f768481ba 100644 --- a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -36,6 +36,8 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~Microsoft.Maui.Controls.WebView.UserAgent.set -> void ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool +~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.BindableObject self, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool +~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.BindableObject bindableObject, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt index ce1ce9c01052..116e082f41bb 100644 --- a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt @@ -23,6 +23,8 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool +~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.BindableObject self, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool +~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.BindableObject bindableObject, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt index 3c4068b91838..0a8284e7e22f 100644 --- a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt @@ -31,6 +31,8 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool +~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.BindableObject self, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool +~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.BindableObject bindableObject, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/RadioButton.cs b/src/Controls/src/Core/RadioButton.cs index 180eb99aea29..73c6a6701e8c 100644 --- a/src/Controls/src/Core/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton.cs @@ -557,11 +557,20 @@ static View BuildDefaultTemplate() out checkMarkVisualStateDark); } - checkMark.TrySetFillFromAppTheme( - RadioButtonCheckGlyphFillLight, - RadioButtonCheckGlyphFillDark, - SolidColorBrush.White, - SolidColorBrush.Black); + if (!checkMark.TrySetDynamicThemeColor( + RadioButtonCheckMarkThemeColor, + Ellipse.FillProperty, + out dynamicCheckMarkThemeColor)) + { + checkMark.TrySetAppTheme( + RadioButtonCheckGlyphFillLight, + RadioButtonCheckGlyphFillDark, + Ellipse.FillProperty, + SolidColorBrush.White, + SolidColorBrush.Black, + out _, + out _); + } contentPresenter.SetBinding(MarginProperty, new Binding("Padding", source: RelativeBindingSource.TemplatedParent)); contentPresenter.SetBinding(BackgroundColorProperty, new Binding(BackgroundColorProperty.PropertyName, From a3a79d1aac724b87c13730722020559870d12375 Mon Sep 17 00:00:00 2001 From: Dustin Wojciechowski Date: Thu, 9 Mar 2023 12:57:07 -0800 Subject: [PATCH 13/15] Changed TrySetAppTheme and TrySetDynamicTheme to internal, removed refs from unshipped api files --- src/Controls/src/Core/BindableObjectExtensions.cs | 4 ++-- .../src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt | 2 -- .../src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt | 2 -- .../Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | 2 -- src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt | 2 -- .../src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt | 2 -- 6 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/Controls/src/Core/BindableObjectExtensions.cs b/src/Controls/src/Core/BindableObjectExtensions.cs index 151fa1aa3147..3adbbb5ed109 100644 --- a/src/Controls/src/Core/BindableObjectExtensions.cs +++ b/src/Controls/src/Core/BindableObjectExtensions.cs @@ -70,7 +70,7 @@ public static T GetPropertyIfSet(this BindableObject bindableObject, Bindable return returnIfNotSet; } - public static bool TrySetDynamicThemeColor( + internal static bool TrySetDynamicThemeColor( this BindableObject bindableObject, string resourceKey, BindableProperty bindableProperty, @@ -85,7 +85,7 @@ public static bool TrySetDynamicThemeColor( return false; } - public static bool TrySetAppTheme( + internal static bool TrySetAppTheme( this BindableObject self, string lightResourceKey, string darkResourceKey, diff --git a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt index 0f628e0b48d5..b58af6e02992 100644 --- a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt @@ -26,8 +26,6 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool -~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.BindableObject self, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool -~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.BindableObject bindableObject, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 86ae82c9f5b2..ceefe7046f1b 100644 --- a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -36,8 +36,6 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~Microsoft.Maui.Controls.WebView.UserAgent.set -> void ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool -~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.BindableObject self, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool -~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.BindableObject bindableObject, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 664f768481ba..29fd1fc277ff 100644 --- a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -36,8 +36,6 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~Microsoft.Maui.Controls.WebView.UserAgent.set -> void ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool -~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.BindableObject self, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool -~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.BindableObject bindableObject, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt index 116e082f41bb..ce1ce9c01052 100644 --- a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt @@ -23,8 +23,6 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool -~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.BindableObject self, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool -~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.BindableObject bindableObject, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~Microsoft.Maui.Controls.IMessagingCenter.Send(TSender sender, string message) -> void diff --git a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt index 0a8284e7e22f..3c4068b91838 100644 --- a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt @@ -31,8 +31,6 @@ override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool ~override Microsoft.Maui.Controls.LayoutOptions.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Region.Equals(object obj) -> bool ~override Microsoft.Maui.Controls.Shapes.Matrix.Equals(object obj) -> bool -~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetAppTheme(this Microsoft.Maui.Controls.BindableObject self, string lightResourceKey, string darkResourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, Microsoft.Maui.Controls.Brush defaultDark, Microsoft.Maui.Controls.Brush defaultLight, out object outerLight, out object outerDark) -> bool -~static Microsoft.Maui.Controls.BindableObjectExtensions.TrySetDynamicThemeColor(this Microsoft.Maui.Controls.BindableObject bindableObject, string resourceKey, Microsoft.Maui.Controls.BindableProperty bindableProperty, out object outerColor) -> bool ~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message, TArgs args) -> void *REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send(TSender sender, string message) -> void From de39082b946b1676cac89ac711dc05d646da336d Mon Sep 17 00:00:00 2001 From: Dustin Wojciechowski Date: Fri, 10 Mar 2023 14:10:27 -0800 Subject: [PATCH 14/15] Update RadioButton.Tizen to match new changes to BuildDefaultTemplate in RadioButton --- .../RadioButton/RadioButton.Tizen.cs | 126 ++++++++++-------- 1 file changed, 72 insertions(+), 54 deletions(-) diff --git a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs index e3bf4dacdbda..ab05132a7a1f 100644 --- a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs +++ b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Tizen.cs @@ -23,20 +23,32 @@ public static void MapContent(IRadioButtonHandler handler, RadioButton radioButt static View BuildTizenDefaultTemplate() { - var frame = new Frame + Border border = new Border() { - HasShadow = false, Padding = 6 }; - BindToTemplatedParent(frame, BackgroundColorProperty, Controls.Frame.BorderColorProperty, Controls.Frame.CornerRadiusProperty, HorizontalOptionsProperty, + BindToTemplatedParent(border, BackgroundColorProperty, HorizontalOptionsProperty, MarginProperty, OpacityProperty, RotationProperty, ScaleProperty, ScaleXProperty, ScaleYProperty, TranslationYProperty, TranslationXProperty, VerticalOptionsProperty); + border.SetBinding(Border.StrokeProperty, + new Binding(BorderColorProperty.PropertyName, + source: RelativeBindingSource.TemplatedParent)); + + border.SetBinding(Border.StrokeShapeProperty, + new Binding(CornerRadiusProperty.PropertyName, converter: new CornerRadiusToShape(), + source: RelativeBindingSource.TemplatedParent)); + + border.SetBinding(Border.StrokeThicknessProperty, + new Binding(BorderWidthProperty.PropertyName, + source: RelativeBindingSource.TemplatedParent)); + var grid = new Grid { - ColumnSpacing = 6, + Padding = 2, RowSpacing = 0, + ColumnSpacing = 6, ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = GridLength.Auto }, new ColumnDefinition { Width = GridLength.Star } @@ -72,58 +84,62 @@ static View BuildTizenDefaultTemplate() var contentPresenter = new ContentPresenter { HorizontalOptions = LayoutOptions.Fill, - VerticalOptions = LayoutOptions.Center + VerticalOptions = LayoutOptions.Fill }; - object outerEllipseVisualStateLight; - object outerEllipseVisualStateDark; - object checkMarkVisualStateLight; - object checkMarkVisualStateDark; - - // First, Light/Dark App themes for outer ellipse, then for the check mark. - // Then check for older themecolor. - // If nothing set, use the defaults for light/dark mode. - if (Application.Current.TryGetResource(RadioButtonOuterEllipseStrokeLight, out var outerLight) && - Application.Current.TryGetResource(RadioButtonOuterEllipseStrokeDark, out var outerDark)) - { - normalEllipse.SetAppTheme(Ellipse.StrokeProperty, outerLight, outerDark); - outerEllipseVisualStateLight = outerLight; - outerEllipseVisualStateDark = outerDark; - } - else if (Application.Current.TryGetResource(RadioButtonThemeColor, out var themeColor)) + object dynamicOuterEllipseThemeColor = null; + object dynamicCheckMarkThemeColor = null; + object outerEllipseVisualStateLight = null; + object outerEllipseVisualStateDark = null; + object checkMarkVisualStateLight = null; + object checkMarkVisualStateDark = null; + + if (!normalEllipse.TrySetDynamicThemeColor( + RadioButtonThemeColor, + Ellipse.StrokeProperty, + out dynamicOuterEllipseThemeColor)) { - normalEllipse.SetDynamicResource(Ellipse.StrokeProperty, RadioButtonThemeColor); - outerEllipseVisualStateLight = outerEllipseVisualStateDark = themeColor; - } - else - { - normalEllipse.SetAppTheme(Ellipse.StrokeProperty, SolidColorBrush.Black, SolidColorBrush.White); - outerEllipseVisualStateLight = SolidColorBrush.Black; - outerEllipseVisualStateDark = SolidColorBrush.White; + normalEllipse.TrySetAppTheme( + RadioButtonOuterEllipseStrokeLight, + RadioButtonOuterEllipseStrokeDark, + Ellipse.StrokeProperty, + SolidColorBrush.White, + SolidColorBrush.Black, + out outerEllipseVisualStateLight, + out outerEllipseVisualStateDark); } - if (Application.Current.TryGetResource(RadioButtonCheckGlyphStrokeLight, out var checkLight) && - Application.Current.TryGetResource(RadioButtonCheckGlyphStrokeDark, out var checkDark)) - { - checkMark.SetAppTheme(Ellipse.StrokeProperty, checkLight, checkDark); - checkMark.Fill = (Brush)(Application.Current?.RequestedTheme == AppTheme.Dark ? checkDark : checkLight); - checkMarkVisualStateLight = checkLight; - checkMarkVisualStateDark = checkDark; - } - else if (Application.Current.TryGetResource(RadioButtonCheckMarkThemeColor, out var themeColor)) + if (!checkMark.TrySetDynamicThemeColor( + RadioButtonCheckMarkThemeColor, + Ellipse.StrokeProperty, + out dynamicCheckMarkThemeColor)) { - checkMark.SetDynamicResource(Ellipse.StrokeProperty, RadioButtonCheckMarkThemeColor); - checkMark.Fill = (Brush)themeColor; - checkMarkVisualStateLight = checkMarkVisualStateDark = themeColor; + checkMark.TrySetAppTheme( + RadioButtonCheckGlyphStrokeLight, + RadioButtonCheckGlyphStrokeDark, + Ellipse.StrokeProperty, + SolidColorBrush.White, + SolidColorBrush.Black, + out checkMarkVisualStateLight, + out checkMarkVisualStateDark); } - else + + if (!checkMark.TrySetDynamicThemeColor( + RadioButtonCheckMarkThemeColor, + Ellipse.FillProperty, + out dynamicCheckMarkThemeColor)) { - checkMark.SetAppTheme(Ellipse.StrokeProperty, SolidColorBrush.Black, SolidColorBrush.White); - checkMark.Fill = (Application.Current?.RequestedTheme == AppTheme.Dark) ? SolidColorBrush.White : SolidColorBrush.Black; - checkMarkVisualStateLight = SolidColorBrush.Black; - checkMarkVisualStateDark = SolidColorBrush.White; + checkMark.TrySetAppTheme( + RadioButtonCheckGlyphFillLight, + RadioButtonCheckGlyphFillDark, + Ellipse.FillProperty, + SolidColorBrush.White, + SolidColorBrush.Black, + out _, + out _); } + contentPresenter.SetBinding(MarginProperty, new Binding("Padding", source: RelativeBindingSource.TemplatedParent)); contentPresenter.SetBinding(BackgroundColorProperty, new Binding(BackgroundColorProperty.PropertyName, source: RelativeBindingSource.TemplatedParent)); @@ -131,11 +147,11 @@ static View BuildTizenDefaultTemplate() grid.Add(checkMark); grid.Add(contentPresenter, 1, 0); - frame.Content = grid; + border.Content = grid; INameScope nameScope = new NameScope(); - NameScope.SetNameScope(frame, nameScope); - nameScope.RegisterName(TemplateRootName, frame); + NameScope.SetNameScope(border, nameScope); + nameScope.RegisterName(TemplateRootName, border); nameScope.RegisterName(UncheckedButton, normalEllipse); nameScope.RegisterName(CheckedIndicator, checkMark); nameScope.RegisterName("ContentPresenter", contentPresenter); @@ -157,33 +173,35 @@ static View BuildTizenDefaultTemplate() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, - Value = new AppThemeBinding() { Light = outerEllipseVisualStateLight, Dark = outerEllipseVisualStateDark } + Value = dynamicOuterEllipseThemeColor is not null ? dynamicOuterEllipseThemeColor : new AppThemeBinding() { Light = outerEllipseVisualStateLight, Dark = outerEllipseVisualStateDark } }); checkedVisualState.Setters.Add( new Setter() { Property = Shape.StrokeProperty, TargetName = CheckedIndicator, - Value = new AppThemeBinding() { Light = checkMarkVisualStateLight, Dark = checkMarkVisualStateDark } + Value = dynamicCheckMarkThemeColor is not null ? dynamicCheckMarkThemeColor : new AppThemeBinding() { Light = checkMarkVisualStateLight, Dark = checkMarkVisualStateDark } }); checkedStates.States.Add(checkedVisualState); VisualState uncheckedVisualState = new VisualState() { Name = UncheckedVisualState }; uncheckedVisualState.Setters.Add(new Setter() { Property = OpacityProperty, TargetName = CheckedIndicator, Value = 0 }); + uncheckedVisualState.Setters.Add( new Setter() { Property = Shape.StrokeProperty, TargetName = UncheckedButton, - Value = new AppThemeBinding() { Light = outerEllipseVisualStateLight, Dark = outerEllipseVisualStateDark } + Value = dynamicOuterEllipseThemeColor is not null ? dynamicOuterEllipseThemeColor : new AppThemeBinding() { Light = outerEllipseVisualStateLight, Dark = outerEllipseVisualStateDark } }); + checkedStates.States.Add(uncheckedVisualState); visualStateGroups.Add(checkedStates); - VisualStateManager.SetVisualStateGroups(frame, visualStateGroups); + VisualStateManager.SetVisualStateGroups(border, visualStateGroups); - return frame; + return border; } } } \ No newline at end of file From 1b3e834f981ddfe3d301c9758598b1d1c6e00783 Mon Sep 17 00:00:00 2001 From: Dustin Wojciechowski Date: Mon, 13 Mar 2023 10:24:27 -0700 Subject: [PATCH 15/15] Updated test to use Border instead of Frame --- src/Controls/tests/Core.UnitTests/AppThemeTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controls/tests/Core.UnitTests/AppThemeTests.cs b/src/Controls/tests/Core.UnitTests/AppThemeTests.cs index 114a41e37f00..f8e60f70dde4 100644 --- a/src/Controls/tests/Core.UnitTests/AppThemeTests.cs +++ b/src/Controls/tests/Core.UnitTests/AppThemeTests.cs @@ -197,8 +197,8 @@ public void ThemeBindingRemovedOnOneTimeBindablePropertyWhenPropertySet() void validateRadioButtonColors(RadioButton button, SolidColorBrush desiredBrush) { - var frame = (Frame)button.Children[0]; - var grid = (Grid)frame.Children[0]; + var border = (Border)button.Children[0]; + var grid = (Grid)border.Content; var outerEllipse = (Shapes.Ellipse)grid.Children[0]; var innerEllipse = (Shapes.Ellipse)grid.Children[1];