Introducing Xamarin.Forms Date Picker | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (215)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (915)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (628)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (592)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Xamarin Forms Date Picker

Introducing Xamarin.Forms Date Picker

Date Picker is a new component introduced to Syncfusion’s Xamarin.Forms component list in Essential Studio 2019 Volume 4. Date Picker is a fully customizable component that provides a simple, yet attractive UI to give your application a smooth and touch-friendly experience. This component provides a common UI for all platforms and can be used in scheduling, to-do, and reminder applications.

In this article, I will walk you through the features available in this new Date Picker component.

Formatting the picker

Xamarin.Forms Date Picker shows the date values to be picked from in four predefined date formats. The Date Picker component also provides support for formatting the text of the column and the header. The following code example illustrates the “yyyy MM dd” format loaded in Date Picker.

 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:DatePickerSample"
             xmlns:datepicker="clr-namespace:Syncfusion.XForms.Pickers;assembly=Syncfusion.SfPicker.XForms"
             x:Class="DatePickerSample.MainPage" >
     <ContentPage.Content >
         <Grid >
             <datepicker:SfDatePicker PickerMode="Dialog"
                                     Format="yyyy_MM_dd"
                                     ShowFooter="True"/ >
         </Grid >
     </ContentPage.Content >
 </ContentPage >

Formatting Xamarin.Forms Date Picker.
Formatting Xamarin.Forms Date Picker

Dialog and Standalone

A compact view of the elements in the screen is one of the most important aspects of an application.  Date Picker comes with a standalone mode and a dialog mod, which renders the picker at the center of the application window; it makes the app looks more impressive in the UI.

 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:DatePickerSample"
    xmlns:datepicker="clr-namespace:Syncfusion.XForms.Pickers;assembly=Syncfusion.SfPicker.XForms"
    x:Class="DatePickerSample.MainPage" >
         <Grid >
             <datepicker:SfDatePicker x:Name="datePicker"
                                     PickerMode="Dialog"
                                     Format="yyyy_MM_dd"
                                     ShowFooter="True"/ >
         <Button Clicked="PickerButton_Clicked" .../ >
     </Grid >
 </ContentPage  >
public partial class MainPage
{
    public MainPage()
    { 
        InitializeComponent();
    }
    private void PickerButton_Clicked(object sender,             System.EventArgs e)
    {
        this.datePicker.IsOpen = true;
    }
}
Xamarin.Forms Date Picker in Dialog View Mode.
Xamarin.Forms Date Picker in Dialog View Mode

Specify minimum and maximum dates

Date Picker can be loaded with a specified date range by setting the maximum and minimum dates to restrict selecting a date beyond the range.

 <datepicker:SfDatePicker MinimumDate="03/29/2000"
                         MaximumDate="05/05/2021" .../ >
Xamarin.Forms Date Picker Validation.
Xamarin.Forms Date Picker Validation

Date values with intervals

Date values can be populated with intervals in Date Picker for days, months, and years individually.

 <datepicker:SfDatePicker PickerMode="Dialog"
                         DayInterval="2"
                         MonthInterval="2"
                         YearInterval="2" .../ >
Setting Interval in Xamarin.Forms Date Picker.
Setting Interval in Xamarin.Forms Date Picker

Customization

You can customize the colors and fonts of the headers, column headers, footer, and date values. The following code example shows how the selected values and unselected values are customized along with fonts.

 <datepicker:SfDatePicker PickerMode="Dialog"
                         HeaderText="SELECT A DATE"
                         HeaderBackgroundColor="#238F94"
                         HeaderTextColor="#FFFFFF"
                         OKButtonTextColor="#238F94"
                         CancelButtonTextColor="#238F94"
                         UnselectedItemTextColor="#238F94"
                         ColumnHeaderBackgroundColor="#EBF2F2"
                         SelectedItemTextColor="#238F94"
                         ShowFooter="True"/ >
Customizing Xamarin.Forms Date Picker.
Customizing Xamarin.Forms Date Picker

Creating a Xamarin.Forms application containing the Date Picker

This section explains the step-by-step procedure for implementing the Date Picker control in a Xamarin.Forms application using Visual Studio:

  1. Create a blank Xamarin.Forms application.
  2. In the application, reference the SfPickerNuGet package from nuget.org. To learn more about SfDatePicker, refer to the Adding SfDatePicker reference documentation.
  3. When deploying the application in UWP and iOS, follow the steps provided in Launching the application on each platform with Date Picker in the documentation.
  4. Import the Date Picker namespace in your page and initialize SfDatePicker as demonstrated in the following code sample.
 <?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:local="clr-namespace:DatePickerSample"
             xmlns:datepicker="clr-namespace:Syncfusion.XForms.Pickers;assembly=Syncfusion.SfPicker.XForms"
             x:Class="DatePickerSample.MainPage" >
     <ContentPage.Content >
         <Grid >
             <datepicker:SfDatePicker x:Name="datePicker"
                                     PickerMode="Dialog"
                                     PickerWidth="300"
                                     ShowFooter="True"/ >
             <Button Text="Open date Picker" 
                    x:Name="pickerButton"
                    Clicked="PickerButton_Clicked"
                    …./ >
         </Grid >
     </ContentPage.Content >
 </ContentPage >
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void PickerButton_Clicked(object sender, System.EventArgs e)
        {
            this.datePicker.IsOpen = true;
        }
    }
Creating a Xamarin.Forms Application Containing Date Picker.
Creating a Xamarin.Forms Application Containing Date Picker

You can download a basic sample from the Getting Started section of our Date Picker control documentation.

Conclusion

In this blog post, we walked through our new Xamarin.Forms Date Picker component and its features. Try this control with our 2019 Volume 4 release. To learn more about this component, refer to our UG documentation. You can drop your comments in the section below if you need any clarification about this component.

Try our Date Picker component with the sample project available in this GitHub location. You can also explore our AndroidiOS and UWP demo apps.

If you need support for specific features in this component or have any questions, contact us through our support forumDirect-Trac, or feedback portal. We are waiting to hear your feedback about this new component!

If you like this article, then we believe you will also like the following article and ebooks

[Blog] Introducing Xamarin.Forms Time Picker

[eBook] Xamarin.Forms Succinctly

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed