Added DatePickerRenderer
This commit is contained in:
Родитель
4b8126a9d2
Коммит
bff7ae7d05
|
@ -46,11 +46,15 @@
|
|||
x:Name="openglView"
|
||||
Grid.Column="0" Grid.Row="2"
|
||||
/>-->
|
||||
<BoxView
|
||||
<!--<BoxView
|
||||
Color="Blue"
|
||||
Rotation="30"
|
||||
Scale="0.1"
|
||||
Grid.Column="0" Grid.Row="2"
|
||||
/>-->
|
||||
<DatePicker
|
||||
x:Name="datePicker"
|
||||
Grid.Column="0" Grid.Row="2"
|
||||
/>
|
||||
<Label
|
||||
Grid.Column="1" Grid.Row="2"
|
||||
|
|
|
@ -51,5 +51,6 @@ using Xamarin.Forms.Platform.WinForms;
|
|||
[assembly: ExportRenderer(typeof(Picker), typeof(PickerRenderer))]
|
||||
[assembly: ExportRenderer(typeof(ActivityIndicator), typeof(ActivityIndicatorRenderer))]
|
||||
[assembly: ExportRenderer(typeof(BoxView), typeof(BoxViewRenderer))]
|
||||
[assembly: ExportRenderer(typeof(DatePicker), typeof(DatePickerRenderer))]
|
||||
[assembly: ExportRenderer(typeof(OpenGLView), typeof(OpenGLViewRenderer))]
|
||||
[assembly: ExportRenderer(typeof(WebView), typeof(WebViewRenderer))]
|
||||
|
|
|
@ -6,20 +6,75 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Xamarin.Forms.Platform.WinForms
|
||||
{
|
||||
public class DatePickerRenderer : ViewRenderer<Button, System.Windows.Forms.DateTimePicker>
|
||||
public class DatePickerRenderer : ViewRenderer<DatePicker, System.Windows.Forms.DateTimePicker>
|
||||
{
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
|
||||
{
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
if (Control == null)
|
||||
{
|
||||
SetNativeControl(new System.Windows.Forms.DateTimePicker());
|
||||
Control.ValueChanged += DateTimePicker_OnValueChanged;
|
||||
}
|
||||
|
||||
// Update control property
|
||||
UpdateDate(Control);
|
||||
UpdateMinimumDate(Control);
|
||||
UpdateMaximumDate(Control);
|
||||
UpdateTextColor(Control);
|
||||
}
|
||||
|
||||
base.OnElementChanged(e);
|
||||
}
|
||||
|
||||
void UpdateDate(System.Windows.Forms.DateTimePicker nativeElement)
|
||||
{
|
||||
var element = Element;
|
||||
if (nativeElement != null && element != null)
|
||||
{
|
||||
nativeElement.Value = Element.Date;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateMaximumDate(System.Windows.Forms.DateTimePicker nativeElement)
|
||||
{
|
||||
var element = Element;
|
||||
if (nativeElement != null && element != null)
|
||||
{
|
||||
nativeElement.MaxDate = Element.MaximumDate;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateMinimumDate(System.Windows.Forms.DateTimePicker nativeElement)
|
||||
{
|
||||
var element = Element;
|
||||
if (nativeElement != null && element != null)
|
||||
{
|
||||
nativeElement.MinDate = Element.MinimumDate;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateTextColor(System.Windows.Forms.DateTimePicker nativeElement)
|
||||
{
|
||||
var element = Element;
|
||||
if (nativeElement != null && element != null)
|
||||
{
|
||||
var color = element.TextColor;
|
||||
nativeElement.ForeColor =
|
||||
color == Color.Default ?
|
||||
System.Drawing.SystemColors.ControlText :
|
||||
color.ToWindowsColor();
|
||||
}
|
||||
}
|
||||
|
||||
void DateTimePicker_OnValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
var nativeElement = Control;
|
||||
if (nativeElement != null)
|
||||
{
|
||||
((IElementController)Element).SetValueFromRenderer(DatePicker.DateProperty, nativeElement.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче