Implement Time property in WinUI TimePickerHandler

This commit is contained in:
Javier Suárez Ruiz 2021-04-13 13:11:45 +02:00
Родитель fc90bf6c40
Коммит d9972a73dc
3 изменённых файлов: 29 добавлений и 5 удалений

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

@ -161,6 +161,7 @@ namespace Microsoft.Maui.Controls.Compatibility.Platform.UWP
_fontApplied = true;
}
[PortHandler]
void UpdateTime()
{
Control.Time = Element.Time;

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

@ -1,16 +1,18 @@
using System;
using Microsoft.UI.Xaml.Controls;
namespace Microsoft.Maui.Handlers
{
public partial class TimePickerHandler : ViewHandler<ITimePicker, Microsoft.UI.Xaml.Controls.TimePicker>
public partial class TimePickerHandler : ViewHandler<ITimePicker, TimePicker>
{
protected override Microsoft.UI.Xaml.Controls.TimePicker CreateNativeView() => new Microsoft.UI.Xaml.Controls.TimePicker();
protected override TimePicker CreateNativeView() => new TimePicker();
[MissingMapper]
public static void MapFormat(TimePickerHandler handler, ITimePicker view) { }
[MissingMapper]
public static void MapTime(TimePickerHandler handler, ITimePicker view) { }
public static void MapTime(TimePickerHandler handler, ITimePicker timePicker)
{
handler.NativeView?.UpdateTime(timePicker);
}
[MissingMapper]
public static void MapCharacterSpacing(TimePickerHandler handler, ITimePicker view) { }

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

@ -0,0 +1,21 @@
using Microsoft.UI.Xaml.Controls;
namespace Microsoft.Maui
{
public static class TimePickerExtensions
{
public static void UpdateTime(this TimePicker nativeTimePicker, ITimePicker timePicker)
{
nativeTimePicker.Time = timePicker.Time;
if (timePicker.Format?.Contains('H') == true)
{
nativeTimePicker.ClockIdentifier = "24HourClock";
}
else
{
nativeTimePicker.ClockIdentifier = "12HourClock";
}
}
}
}