Implement basic Slider properties in WinUI

This commit is contained in:
Javier Suárez Ruiz 2021-04-13 12:31:36 +02:00
Родитель fc90bf6c40
Коммит 14e4926a41
3 изменённых файлов: 87 добавлений и 18 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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<ISlider, Slider>
{
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) { }
}
}

Просмотреть файл

@ -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();
}
}
}