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 c267597f7c7a..d0203ec355a0 100644 --- a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt @@ -146,3 +146,6 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty! static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty! virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void +~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color +~Microsoft.Maui.Controls.Switch.OffColor.set -> void \ No newline at end of file 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 18f78ab6025e..4aaf43b7b771 100644 --- a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -339,3 +339,6 @@ virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewController2 virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewDelegator2.GetVisibleItemsIndex() -> (bool VisibleItems, int First, int Center, int Last) virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2.UpdateLayout() -> void override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.MovedToWindow() -> void +~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color +~Microsoft.Maui.Controls.Switch.OffColor.set -> void \ No newline at end of file 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 18f78ab6025e..4aaf43b7b771 100644 --- a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -339,3 +339,6 @@ virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewController2 virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewDelegator2.GetVisibleItemsIndex() -> (bool VisibleItems, int First, int Center, int Last) virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2.UpdateLayout() -> void override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.MovedToWindow() -> void +~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color +~Microsoft.Maui.Controls.Switch.OffColor.set -> void \ No newline at end of file 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 b0deac289648..6dea6ec6b028 100644 --- a/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt @@ -141,3 +141,6 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty! static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty! virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void +~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color +~Microsoft.Maui.Controls.Switch.OffColor.set -> void 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 8be85a498fa7..33edca54fdb1 100644 --- a/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt @@ -146,3 +146,6 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty! static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty! virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void +~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color +~Microsoft.Maui.Controls.Switch.OffColor.set -> void \ No newline at end of file diff --git a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt index b0deac289648..3f898cb631be 100644 --- a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt @@ -141,3 +141,6 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty! static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty! virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void +~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color +~Microsoft.Maui.Controls.Switch.OffColor.set -> void \ No newline at end of file diff --git a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt index b0deac289648..6dea6ec6b028 100644 --- a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt @@ -141,3 +141,6 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty! static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty! virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void +~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty +~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color +~Microsoft.Maui.Controls.Switch.OffColor.set -> void diff --git a/src/Controls/src/Core/Switch/Switch.cs b/src/Controls/src/Core/Switch/Switch.cs index faf74a977e6c..06c2d0ccf542 100644 --- a/src/Controls/src/Core/Switch/Switch.cs +++ b/src/Controls/src/Core/Switch/Switch.cs @@ -29,6 +29,13 @@ public partial class Switch : View, IElementConfiguration, ISwitch ((IView)bindable)?.Handler?.UpdateValue(nameof(ISwitch.TrackColor)); }); + /// Bindable property for . + public static readonly BindableProperty OffColorProperty = BindableProperty.Create(nameof(OffColor), typeof(Color), typeof(Switch), null, + propertyChanged: (bindable, oldValue, newValue) => + { + ((IView)bindable)?.Handler?.UpdateValue(nameof(ISwitch.TrackColor)); + }); + /// Bindable property for . public static readonly BindableProperty ThumbColorProperty = BindableProperty.Create(nameof(ThumbColor), typeof(Color), typeof(Switch), null); @@ -39,6 +46,17 @@ public Color OnColor set { SetValue(OnColorProperty, value); } } + /// + /// Gets or sets the color of the toggle switch's track when it is in the off state. + /// If not set, the default color will be used for the off-track appearance. + /// + public Color OffColor + { + get { return (Color) GetValue(OffColorProperty); } + set { SetValue(OffColorProperty, value); } + } + + /// public Color ThumbColor { @@ -91,14 +109,14 @@ Color ISwitch.TrackColor { get { -#if WINDOWS - return OnColor; -#else if (IsToggled) + { return OnColor; - - return null; -#endif + } + else + { + return OffColor; + } } } diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifySwitchOffColorAfterToggling.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifySwitchOffColorAfterToggling.png new file mode 100644 index 000000000000..037861604ba5 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifySwitchOffColorAfterToggling.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue15695.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue15695.xaml new file mode 100644 index 000000000000..d1f1d3ae5282 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue15695.xaml @@ -0,0 +1,10 @@ + + + + + +