diff --git a/src/Compatibility/Core/src/Windows/SliderRenderer.cs b/src/Compatibility/Core/src/Windows/SliderRenderer.cs index f7f281f92..88793dbea 100644 --- a/src/Compatibility/Core/src/Windows/SliderRenderer.cs +++ b/src/Compatibility/Core/src/Windows/SliderRenderer.cs @@ -101,6 +101,7 @@ namespace Microsoft.Maui.Controls.Compatibility.Platform.UWP UpdateMaximumTrackColor(); } + [PortHandler] void UpdateMinimumTrackColor() { if (Control != null) @@ -112,6 +113,7 @@ namespace Microsoft.Maui.Controls.Compatibility.Platform.UWP } } + [PortHandler] void UpdateMaximumTrackColor() { if (Control != null) diff --git a/src/Core/src/Handlers/Slider/SliderHandler.Windows.cs b/src/Core/src/Handlers/Slider/SliderHandler.Windows.cs index d019fe860..244bece65 100644 --- a/src/Core/src/Handlers/Slider/SliderHandler.Windows.cs +++ b/src/Core/src/Handlers/Slider/SliderHandler.Windows.cs @@ -1,28 +1,55 @@ -using System; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; namespace Microsoft.Maui.Handlers { public partial class SliderHandler : ViewHandler { - protected override Slider CreateNativeView() => new Slider(); + static Brush? DefaultForegroundColor; + static Brush? DefaultBackgroundColor; + + protected override Slider CreateNativeView() + { + var slider = new Slider + { + IsThumbToolTipEnabled = false + }; + + return slider; + } + + protected override void SetupDefaults(Slider nativeView) + { + DefaultForegroundColor = nativeView.Foreground; + DefaultBackgroundColor = nativeView.Background; + } + + public static void MapMinimum(SliderHandler handler, ISlider slider) + { + handler.NativeView?.UpdateMinimum(slider); + } + + public static void MapMaximum(SliderHandler handler, ISlider slider) + { + handler.NativeView?.UpdateMaximum(slider); + } + + public static void MapValue(SliderHandler handler, ISlider slider) + { + handler.NativeView?.UpdateValue(slider); + } + + public static void MapMinimumTrackColor(SliderHandler handler, ISlider slider) + { + handler.NativeView?.UpdateMinimumTrackColor(slider, DefaultForegroundColor); + } + + public static void MapMaximumTrackColor(SliderHandler handler, ISlider slider) + { + handler.NativeView?.UpdateMaximumTrackColor(slider, DefaultBackgroundColor); + } [MissingMapper] - public static void MapMinimum(IViewHandler handler, ISlider slider) { } - - [MissingMapper] - public static void MapMaximum(IViewHandler handler, ISlider slider) { } - - [MissingMapper] - public static void MapValue(IViewHandler handler, ISlider slider) { } - - [MissingMapper] - public static void MapMinimumTrackColor(IViewHandler handler, ISlider slider) { } - - [MissingMapper] - public static void MapMaximumTrackColor(IViewHandler handler, ISlider slider) { } - - [MissingMapper] - public static void MapThumbColor(IViewHandler handler, ISlider slider) { } + public static void MapThumbColor(SliderHandler handler, ISlider slider) { } } } \ No newline at end of file diff --git a/src/Core/src/Platform/Windows/SliderExtensions.cs b/src/Core/src/Platform/Windows/SliderExtensions.cs new file mode 100644 index 000000000..97088e749 --- /dev/null +++ b/src/Core/src/Platform/Windows/SliderExtensions.cs @@ -0,0 +1,40 @@ +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; + +namespace Microsoft.Maui +{ + public static class SliderExtensions + { + public static void UpdateMinimum(this Slider nativeSlider, ISlider slider) + { + nativeSlider.Minimum = slider.Minimum; + } + + public static void UpdateMaximum(this Slider nativeSlider, ISlider slider) + { + nativeSlider.Maximum = slider.Maximum; + } + + public static void UpdateValue(this Slider nativeSlider, ISlider slider) + { + if (nativeSlider.Value != slider.Value) + nativeSlider.Value = slider.Value; + } + + public static void UpdateMinimumTrackColor(this Slider nativeSlider, ISlider slider, Brush? defaultForegroundColor) + { + if (slider.MinimumTrackColor == Color.Default) + nativeSlider.Foreground = defaultForegroundColor; + else + nativeSlider.Foreground = slider.MinimumTrackColor.ToNative(); + } + + public static void UpdateMaximumTrackColor(this Slider nativeSlider, ISlider slider, Brush? defaultBackgroundColor) + { + if (slider.MaximumTrackColor == Color.Default) + nativeSlider.Background = defaultBackgroundColor; + else + nativeSlider.Background = slider.MaximumTrackColor.ToNative(); + } + } +} \ No newline at end of file