94 строки
3.1 KiB
C#
94 строки
3.1 KiB
C#
using System;
|
|
using Xamarin.Forms.Internals;
|
|
using Xamarin.Forms.Platform;
|
|
|
|
namespace Xamarin.Forms
|
|
{
|
|
[RenderWith(typeof(_TimePickerRenderer))]
|
|
public class TimePicker : View, IFontElement, ITextElement, IElementConfiguration<TimePicker>
|
|
{
|
|
public static readonly BindableProperty FormatProperty = BindableProperty.Create(nameof(Format), typeof(string), typeof(TimePicker), "t");
|
|
|
|
public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty;
|
|
|
|
public static readonly BindableProperty TimeProperty = BindableProperty.Create(nameof(Time), typeof(TimeSpan), typeof(TimePicker), new TimeSpan(0), BindingMode.TwoWay, (bindable, value) =>
|
|
{
|
|
var time = (TimeSpan)value;
|
|
return time.TotalHours < 24 && time.TotalMilliseconds >= 0;
|
|
});
|
|
|
|
public static readonly BindableProperty FontFamilyProperty = FontElement.FontFamilyProperty;
|
|
|
|
public static readonly BindableProperty FontSizeProperty = FontElement.FontSizeProperty;
|
|
|
|
public static readonly BindableProperty FontAttributesProperty = FontElement.FontAttributesProperty;
|
|
|
|
readonly Lazy<PlatformConfigurationRegistry<TimePicker>> _platformConfigurationRegistry;
|
|
|
|
public TimePicker()
|
|
{
|
|
_platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<TimePicker>>(() => new PlatformConfigurationRegistry<TimePicker>(this));
|
|
}
|
|
|
|
public string Format
|
|
{
|
|
get { return (string)GetValue(FormatProperty); }
|
|
set { SetValue(FormatProperty, value); }
|
|
}
|
|
|
|
public Color TextColor
|
|
{
|
|
get { return (Color)GetValue(TextElement.TextColorProperty); }
|
|
set { SetValue(TextElement.TextColorProperty, value); }
|
|
}
|
|
|
|
public TimeSpan Time
|
|
{
|
|
get { return (TimeSpan)GetValue(TimeProperty); }
|
|
set { SetValue(TimeProperty, value); }
|
|
}
|
|
|
|
public FontAttributes FontAttributes
|
|
{
|
|
get { return (FontAttributes)GetValue(FontAttributesProperty); }
|
|
set { SetValue(FontAttributesProperty, value); }
|
|
}
|
|
|
|
public string FontFamily
|
|
{
|
|
get { return (string)GetValue(FontFamilyProperty); }
|
|
set { SetValue(FontFamilyProperty, value); }
|
|
}
|
|
|
|
[TypeConverter(typeof(FontSizeConverter))]
|
|
public double FontSize
|
|
{
|
|
get { return (double)GetValue(FontSizeProperty); }
|
|
set { SetValue(FontSizeProperty, value); }
|
|
}
|
|
|
|
void IFontElement.OnFontFamilyChanged(string oldValue, string newValue) =>
|
|
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
|
|
|
void IFontElement.OnFontSizeChanged(double oldValue, double newValue) =>
|
|
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
|
|
|
void IFontElement.OnFontChanged(Font oldValue, Font newValue) =>
|
|
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
|
|
|
double IFontElement.FontSizeDefaultValueCreator() =>
|
|
Device.GetNamedSize(NamedSize.Default, (TimePicker)this);
|
|
|
|
void IFontElement.OnFontAttributesChanged(FontAttributes oldValue, FontAttributes newValue) =>
|
|
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
|
|
|
|
public IPlatformElementConfiguration<T, TimePicker> On<T>() where T : IConfigPlatform
|
|
{
|
|
return _platformConfigurationRegistry.Value.On<T>();
|
|
}
|
|
|
|
void ITextElement.OnTextColorPropertyChanged(Color oldValue, Color newValue)
|
|
{
|
|
}
|
|
}
|
|
} |