diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarAppearanceTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarAppearanceTracker.cs index a41e0b26291c..09ff20adad3c 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarAppearanceTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarAppearanceTracker.cs @@ -1,4 +1,5 @@ #nullable disable +using System; using Android.Graphics.Drawables; using AndroidX.AppCompat.Widget; using Microsoft.Maui.Controls.Handlers.Compatibility; @@ -26,7 +27,11 @@ public virtual void SetAppearance(AToolbar toolbar, IShellToolbarTracker toolbar } var foreground = appearance.ForegroundColor; - var background = appearance.BackgroundColor; + var background = !Brush.IsNullOrEmpty(appearance.Background) + ? appearance.Background + : appearance.BackgroundColor is not null + ? new SolidColorBrush(appearance.BackgroundColor) + : null; var titleColor = appearance.TitleColor; SetColors(toolbar, toolbarTracker, foreground, background, titleColor); @@ -34,10 +39,10 @@ public virtual void SetAppearance(AToolbar toolbar, IShellToolbarTracker toolbar public virtual void ResetAppearance(AToolbar toolbar, IShellToolbarTracker toolbarTracker) { - SetColors(toolbar, toolbarTracker, ShellRenderer.DefaultForegroundColor, ShellRenderer.DefaultBackgroundColor, ShellRenderer.DefaultTitleColor); + SetColors(toolbar, toolbarTracker, ShellRenderer.DefaultForegroundColor, new SolidColorBrush(ShellRenderer.DefaultBackgroundColor), ShellRenderer.DefaultTitleColor); } - protected virtual void SetColors(AToolbar toolbar, IShellToolbarTracker toolbarTracker, Color foreground, Color background, Color title) + protected virtual void SetColors(AToolbar toolbar, IShellToolbarTracker toolbarTracker, Color foreground, Brush background, Color title) { if (_disposed) return; @@ -48,10 +53,16 @@ protected virtual void SetColors(AToolbar toolbar, IShellToolbarTracker toolbarT return; shellToolbar.BarTextColor = title ?? ShellRenderer.DefaultTitleColor; - shellToolbar.BarBackground = new SolidColorBrush(background ?? ShellRenderer.DefaultBackgroundColor); + shellToolbar.BarBackground = background ?? new SolidColorBrush(ShellRenderer.DefaultBackgroundColor); shellToolbar.IconColor = foreground ?? ShellRenderer.DefaultForegroundColor; } + [Obsolete("Use SetColors(AToolbar, IShellToolbarTracker, Color, Brush, Color) instead.")] + protected virtual void SetColors(AToolbar toolbar, IShellToolbarTracker toolbarTracker, Color foreground, Color background, Color title) + { + SetColors(toolbar, toolbarTracker, foreground, background is not null ? new SolidColorBrush(background) : null, title); + } + #region IDisposable public void Dispose() diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellNavBarAppearanceTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellNavBarAppearanceTracker.cs index 67f8acc8fa15..50a186db2cea 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellNavBarAppearanceTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellNavBarAppearanceTracker.cs @@ -131,11 +131,26 @@ void UpdateiOS13NavigationBarAppearance(UINavigationController controller, Shell navBar.TintColor = _defaultTint; } - // Set BackgroundColor - var background = appearance.BackgroundColor; - - if (background != null) - navigationBarAppearance.BackgroundColor = background.ToPlatform(); + // Set Background (prefer Brush over Color for gradient support) + if (!Brush.IsNullOrEmpty(appearance.Background)) + { + if (appearance.Background is SolidColorBrush solidBrush && solidBrush.Color is not null) + { + navigationBarAppearance.BackgroundColor = solidBrush.Color.ToPlatform(); + } + else + { + var backgroundImage = navBar.GetBackgroundImage(appearance.Background); + if (backgroundImage is not null) + { + navigationBarAppearance.BackgroundImage = backgroundImage; + } + } + } + else if (appearance.BackgroundColor is not null) + { + navigationBarAppearance.BackgroundColor = appearance.BackgroundColor.ToPlatform(); + } // Set TitleColor var titleColor = appearance.TitleColor; diff --git a/src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs b/src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs index 8f7a0d4fff93..7ddcd88fe9b1 100644 --- a/src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs +++ b/src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs @@ -184,10 +184,9 @@ public static void UpdateBarBackground(this AToolbar nativeToolbar, Toolbar tool } else { + nativeToolbar.BackgroundTintMode = null; + nativeToolbar.BackgroundTintList = null; nativeToolbar.UpdateBackground(barBackground); - - if (Brush.IsNullOrEmpty(barBackground)) - nativeToolbar.BackgroundTintMode = null; } } 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 9ca34b51bb08..70c245943443 100644 --- a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt @@ -129,6 +129,11 @@ virtual Microsoft.Maui.Controls.LongPressingEventArgs.GetPosition(Microsoft.Maui ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty ~virtual Microsoft.Maui.Controls.Platform.Compatibility.ShellItemRenderer.UpdateShellSectionBadge(Microsoft.Maui.Controls.ShellSection shellSection, int index) -> void +~Microsoft.Maui.Controls.ShellAppearance.Background.get -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.GetBackground(Microsoft.Maui.Controls.BindableObject obj) -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.SetBackground(Microsoft.Maui.Controls.BindableObject obj, Microsoft.Maui.Controls.Brush value) -> void +~static readonly Microsoft.Maui.Controls.Shell.BackgroundProperty -> Microsoft.Maui.Controls.BindableProperty +~virtual Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarAppearanceTracker.SetColors(AndroidX.AppCompat.Widget.Toolbar toolbar, Microsoft.Maui.Controls.Platform.Compatibility.IShellToolbarTracker toolbarTracker, Microsoft.Maui.Graphics.Color foreground, Microsoft.Maui.Controls.Brush background, Microsoft.Maui.Graphics.Color title) -> void Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.get -> Microsoft.Maui.Controls.FontAttributes Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.set -> void static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty! 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 c6f2a70dac02..86d687042c18 100644 --- a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -129,6 +129,10 @@ virtual Microsoft.Maui.Controls.LongPressingEventArgs.GetPosition(Microsoft.Maui ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.ShellAppearance.Background.get -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.GetBackground(Microsoft.Maui.Controls.BindableObject obj) -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.SetBackground(Microsoft.Maui.Controls.BindableObject obj, Microsoft.Maui.Controls.Brush value) -> void +~static readonly Microsoft.Maui.Controls.Shell.BackgroundProperty -> Microsoft.Maui.Controls.BindableProperty Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.get -> Microsoft.Maui.Controls.FontAttributes Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.set -> void static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty! 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 0cb701ac82ba..57615d708d90 100644 --- a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -121,6 +121,10 @@ virtual Microsoft.Maui.Controls.LongPressingEventArgs.GetPosition(Microsoft.Maui ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.ShellAppearance.Background.get -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.GetBackground(Microsoft.Maui.Controls.BindableObject obj) -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.SetBackground(Microsoft.Maui.Controls.BindableObject obj, Microsoft.Maui.Controls.Brush value) -> void +~static readonly Microsoft.Maui.Controls.Shell.BackgroundProperty -> Microsoft.Maui.Controls.BindableProperty Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.get -> Microsoft.Maui.Controls.FontAttributes Microsoft.Maui.Controls.TitleBar.TitleFontAttributes.set -> void static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> Microsoft.Maui.Controls.BindableProperty! diff --git a/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt index 1328d75a8965..6ab89ba0fff4 100644 --- a/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt @@ -117,6 +117,10 @@ virtual Microsoft.Maui.Controls.LongPressingEventArgs.GetPosition(Microsoft.Maui ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.ShellAppearance.Background.get -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.GetBackground(Microsoft.Maui.Controls.BindableObject obj) -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.SetBackground(Microsoft.Maui.Controls.BindableObject obj, Microsoft.Maui.Controls.Brush value) -> void +~static readonly Microsoft.Maui.Controls.Shell.BackgroundProperty -> Microsoft.Maui.Controls.BindableProperty override Microsoft.Maui.Controls.BindablePropertyConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool override Microsoft.Maui.Controls.BindablePropertyConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool override Microsoft.Maui.Controls.BindablePropertyConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object? diff --git a/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt index 142d9ab89366..6ddee0a9ddde 100644 --- a/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt @@ -164,6 +164,10 @@ virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2.Up ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.ShellAppearance.Background.get -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.GetBackground(Microsoft.Maui.Controls.BindableObject obj) -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.SetBackground(Microsoft.Maui.Controls.BindableObject obj, Microsoft.Maui.Controls.Brush value) -> void +~static readonly Microsoft.Maui.Controls.Shell.BackgroundProperty -> Microsoft.Maui.Controls.BindableProperty override Microsoft.Maui.Controls.BindablePropertyConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool override Microsoft.Maui.Controls.BindablePropertyConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool override Microsoft.Maui.Controls.BindablePropertyConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object? diff --git a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt index 8543028d4f8c..ff27dbb7a2b4 100644 --- a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt @@ -1,4 +1,5 @@ #nullable enable +*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList Microsoft.Maui.Controls.Window.StatusBarTheme.get -> Microsoft.Maui.StatusBarTheme Microsoft.Maui.Controls.Window.StatusBarTheme.set -> void static readonly Microsoft.Maui.Controls.Window.StatusBarThemeProperty -> Microsoft.Maui.Controls.BindableProperty! @@ -115,7 +116,6 @@ static Microsoft.Maui.Controls.ViewExtensions.ScaleXToAsync(this Microsoft.Maui. static Microsoft.Maui.Controls.ViewExtensions.ScaleYToAsync(this Microsoft.Maui.Controls.VisualElement! view, double scale, uint length, Microsoft.Maui.Easing? easing, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task! static Microsoft.Maui.Controls.ViewExtensions.TranslateToAsync(this Microsoft.Maui.Controls.VisualElement! view, double x, double y, uint length, Microsoft.Maui.Easing? easing, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task! ~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> Microsoft.Maui.Controls.VisualStateGroupList -*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList ~static Microsoft.Maui.Controls.VisualStateManager.InvalidateVisualStates(Microsoft.Maui.Controls.VisualElement visualElement) -> void static Microsoft.Maui.Controls.Xaml.Diagnostics.HotReloadDiagnostics.CurrentVersion.get -> int static Microsoft.Maui.Controls.Xaml.Diagnostics.HotReloadDiagnostics.UpdateApplied -> System.EventHandler? @@ -140,6 +140,10 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.ShellAppearance.Background.get -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.GetBackground(Microsoft.Maui.Controls.BindableObject obj) -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.SetBackground(Microsoft.Maui.Controls.BindableObject obj, Microsoft.Maui.Controls.Brush value) -> void +~static readonly Microsoft.Maui.Controls.Shell.BackgroundProperty -> Microsoft.Maui.Controls.BindableProperty override Microsoft.Maui.Controls.BindablePropertyConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool override Microsoft.Maui.Controls.BindablePropertyConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool override Microsoft.Maui.Controls.BindablePropertyConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object? diff --git a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt index 75c769cf6ddb..067390072045 100644 --- a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt @@ -131,6 +131,10 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleFontAttributesProperty -> ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty ~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.ShellAppearance.Background.get -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.GetBackground(Microsoft.Maui.Controls.BindableObject obj) -> Microsoft.Maui.Controls.Brush +~static Microsoft.Maui.Controls.Shell.SetBackground(Microsoft.Maui.Controls.BindableObject obj, Microsoft.Maui.Controls.Brush value) -> void +~static readonly Microsoft.Maui.Controls.Shell.BackgroundProperty -> Microsoft.Maui.Controls.BindableProperty override Microsoft.Maui.Controls.BindablePropertyConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool override Microsoft.Maui.Controls.BindablePropertyConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool override Microsoft.Maui.Controls.BindablePropertyConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object? diff --git a/src/Controls/src/Core/Shell/Shell.cs b/src/Controls/src/Core/Shell/Shell.cs index 24d772ba1999..a49545755fac 100644 --- a/src/Controls/src/Core/Shell/Shell.cs +++ b/src/Controls/src/Core/Shell/Shell.cs @@ -479,6 +479,13 @@ static void OnFlyoutBehaviorChanged(BindableObject bindable, object oldValue, ob BindableProperty.CreateAttached("UnselectedColor", typeof(Color), typeof(Shell), null, propertyChanged: OnShellAppearanceValueChanged); + /// + /// Defines the background brush for the Shell toolbar. Supports gradient brushes. + /// + public static readonly new BindableProperty BackgroundProperty = + BindableProperty.CreateAttached("Background", typeof(Brush), typeof(Shell), Brush.Default, + propertyChanged: OnShellAppearanceValueChanged); + /// /// The backdrop of the flyout, which is the appearance of the flyout overlay. /// @@ -663,6 +670,20 @@ static void OnFlyoutBehaviorChanged(BindableObject bindable, object oldValue, ob /// The brushed used in the backdrop of the flyout. public static void SetFlyoutBackdrop(BindableObject obj, Brush value) => obj.SetValue(FlyoutBackdropProperty, value); + /// + /// Gets the background brush for the Shell toolbar. + /// + /// The object from which to get the background brush. + /// The background brush for the Shell toolbar. + public static Brush GetBackground(BindableObject obj) => (Brush)obj.GetValue(BackgroundProperty); + + /// + /// Sets the background brush for the Shell toolbar. + /// + /// The object on which to set the background brush. + /// The brush to use as the Shell toolbar background. + public static void SetBackground(BindableObject obj, Brush value) => obj.SetValue(BackgroundProperty, value); + static void OnShellAppearanceValueChanged(BindableObject bindable, object oldValue, object newValue) { var item = (Element)bindable; @@ -766,7 +787,14 @@ void UpdateToolbarAppearanceFeatures(Element pivot, ShellAppearance appearance) { appearance = appearance ?? GetAppearanceForPivot(pivot); Toolbar.BarTextColor = appearance?.TitleColor ?? DefaultTitleColor; - Toolbar.BarBackground = appearance?.BackgroundColor ?? DefaultBackgroundColor; + if (!Brush.IsNullOrEmpty(appearance?.Background)) + { + Toolbar.BarBackground = appearance.Background; + } + else + { + Toolbar.BarBackground = appearance?.BackgroundColor ?? DefaultBackgroundColor; + } Toolbar.IconColor = appearance?.ForegroundColor ?? DefaultForegroundColor; } } diff --git a/src/Controls/src/Core/Shell/ShellAppearance.cs b/src/Controls/src/Core/Shell/ShellAppearance.cs index 12bf41d556f9..b439633454a2 100644 --- a/src/Controls/src/Core/Shell/ShellAppearance.cs +++ b/src/Controls/src/Core/Shell/ShellAppearance.cs @@ -26,7 +26,8 @@ public class ShellAppearance : IShellAppearanceElement static readonly BindableProperty[] s_ingestBrushArray = new[] { - Shell.FlyoutBackdropProperty + Shell.FlyoutBackdropProperty, + Shell.BackgroundProperty }; static readonly BindableProperty[] s_ingestDoubleArray = new[] @@ -71,6 +72,9 @@ public class ShellAppearance : IShellAppearanceElement /// Gets the backdrop brush for the Shell flyout. public Brush FlyoutBackdrop => _brushArray[0]; + + /// Gets the background brush of the Shell. + public Brush Background => _brushArray[1]; public double FlyoutWidth => _doubleArray[0]; public double FlyoutHeight => _doubleArray[1]; diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BarBgLinear.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BarBgLinear.png index 8b2bbb4c9f79..001dbc700c48 100644 Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BarBgLinear.png and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BarBgLinear.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BarBgRadial.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BarBgRadial.png index 93cb9ec65df3..80748520d657 100644 Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BarBgRadial.png and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BarBgRadial.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShellBackgroundSupportsGradientBrush.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShellBackgroundSupportsGradientBrush.png new file mode 100644 index 000000000000..dee926279ec1 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShellBackgroundSupportsGradientBrush.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue10445.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue10445.cs new file mode 100644 index 000000000000..9c72e43c885f --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue10445.cs @@ -0,0 +1,45 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 10445, "Shell.Background does not support gradient brushes", PlatformAffected.All)] +public class Issue10445 : TestShell +{ + protected override void Init() + { + FlyoutBehavior = FlyoutBehavior.Disabled; + var gradientBrush = new LinearGradientBrush + { + StartPoint = new Point(0, 0), + EndPoint = new Point(1, 1), + GradientStops = new GradientStopCollection + { + new GradientStop(Colors.Yellow, 0.0f), + new GradientStop(Colors.Green, 1.0f) + } + }; + + Shell.SetBackground(this, gradientBrush); + + var page = new ContentPage + { + Title = "Gradient Shell", + Content = new VerticalStackLayout + { + Padding = 20, + Spacing = 10, + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Center, + Children = + { + new Label + { + Text = "Shell.Background should display a gradient (Yellow to Green) in the navigation bar above.", + AutomationId = "GradientInfoLabel", + HorizontalTextAlignment = TextAlignment.Center + } + } + } + }; + + AddContentPage(page, "Home"); + } +} diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShellBackgroundSupportsGradientBrush.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShellBackgroundSupportsGradientBrush.png new file mode 100644 index 000000000000..5230182925c7 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShellBackgroundSupportsGradientBrush.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue10445.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue10445.cs new file mode 100644 index 000000000000..68ed48ff75c3 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue10445.cs @@ -0,0 +1,25 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue10445 : _IssuesUITest +{ + public Issue10445(TestDevice device) : base(device) + { + } + + public override string Issue => "Shell.Background does not support gradient brushes"; + + [Test] + [Category(UITestCategories.Shell)] + public void ShellBackgroundSupportsGradientBrush() + { + // Wait for the page to be fully loaded + App.WaitForElement("GradientInfoLabel"); + + // Verify the Shell renders correctly with a gradient background + VerifyScreenshot(); + } +} diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShellBackgroundSupportsGradientBrush.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShellBackgroundSupportsGradientBrush.png new file mode 100644 index 000000000000..59a58276da33 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShellBackgroundSupportsGradientBrush.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShellBackgroundSupportsGradientBrush.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShellBackgroundSupportsGradientBrush.png new file mode 100644 index 000000000000..9067ba6fd620 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShellBackgroundSupportsGradientBrush.png differ