DatePicker.MaxYear Property


Gets or sets the maximum Gregorian year available for picking.

 property DateTime MaxYear { DateTime get(); void set(DateTime value); };
DateTime MaxYear();

void MaxYear(DateTime value);
public System.DateTimeOffset MaxYear { get; set; }
var dateTime = datePicker.maxYear;
datePicker.maxYear = dateTime;
Public Property MaxYear As DateTimeOffset

Property Value

DateTime DateTimeOffset

The maximum Gregorian year available for picking.


This example demonstrates setting the MinYear and MaxYear properties in code.

<DatePicker x:Name="myDatePicker"/>
public MainPage()
    myDatePicker.MinYear = new DateTimeOffset(new DateTime(1950, 1, 1));
    myDatePicker.MaxYear = DateTimeOffset.Now.AddYears(5);


You can set the MinYear and MaxYear properties to restrict the date values in the picker. By default, MinYear is set to 100 years prior to the current date and MaxYear is set to 100 years past the current date.

If you set only MinYear or MaxYear, you need to ensure that a valid date range is created by the date you set and the default value of the other date; otherwise, no date will be available to select in the picker. For example, setting only yearDatePicker.MaxYear = new DateTimeOffset(new DateTime(900, 1, 1)); creates an invalid date range with the default value of MinYear.

The MaxYear property can't be set as a XAML attribute string, because the Windows Runtime XAML parser doesn't have a conversion logic for converting strings to dates as DateTime / DateTimeOffset objects. Here are some suggested ways these objects can be defined in code and set to a date other than the current date.

Another possible technique is to define a date that's available as a data object or in the data context, then set MaxYear as a XAML attribute that references a {Binding} markup extension that can access the date as data.

Applies to

See also