In Xamarin Form project create ExtendedDatePicker that Inherit the DatePicker Class.
ExtendedDatePicker.cs
using System; using System.Collections.Generic; using System.Text; using Xamarin.Forms; namespace Mechat.Renderer { public class ExtendedDatePicker : DatePicker { } }
Xamarin.Android
Then in Android Project Create the Class ExtendedDatePickerRenderer.cs that Inherit the DatePickerRenderer.
ExtendedDatePickerRenderer.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget; using Mechat.Droid.Renderer; using Mechat.Renderer; using Xamarin.Forms; using Xamarin.Forms.Platform.Android; [assembly:ExportRenderer(typeof(ExtendedDatePicker), typeof(ExtendedDatePickerRenderer))] namespace Mechat.Droid.Renderer { public class ExtendedDatePickerRenderer : DatePickerRenderer { public ExtendedDatePickerRenderer(Context context) : base(context) { } protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.DatePicker> e) { base.OnElementChanged(e); if (Control != null) { Control.Text = "Select Birthdate"; } } } }
Xamarin.iOS
Then in iOS Project Create the Class ExtendedDatePickerRenderer.cs
ExtendedHtmlLabelRenderer.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Foundation; using Mechat.iOS.Renderer; using Mechat.Renderer; using UIKit; using Xamarin.Forms; using Xamarin.Forms.Platform.iOS; [assembly: ExportRenderer(typeof(ExtendedDatePicker), typeof(ExtendedDatePickerRenderer))] namespace Mechat.iOS.Renderer { public class ExtendedDatePickerRenderer : DatePickerRenderer { protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e) { base.OnElementChanged(e); if (Control != null) { Control.Text = "Select Birthdate"; } } } }
Now implement this Renderer on Xamairn Page.
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:xamAuth="xamarin.a" mc:Ignorable="d" xmlns:local="clr-namespace:Mechat.Renderer" x:Class="Mechat.MainPage"> <StackLayout Margin="10"> <Label Text="Normal datepicker" /> <DatePicker /> <Label Text="Extended Date picker" /> <local:ExtendedDatePicker /> </StackLayout> </ContentPage>
Top 60 Xamarin Blog