Skip to content

Latest commit

 

History

History
54 lines (34 loc) · 3.14 KB

datepicker_maxyear.md

File metadata and controls

54 lines (34 loc) · 3.14 KB
-api-id -api-type
P:Windows.UI.Xaml.Controls.DatePicker.MaxYear
winrt property

Windows.UI.Xaml.Controls.DatePicker.MaxYear

-description

Gets or sets the maximum Gregorian year available for picking.

-property-value

The maximum Gregorian year available for picking.

-remarks

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.

-examples

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

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

-see-also

MinYear, Date picker