Setting Mindate and MaxDate for Datepicker Control
Asked Answered
M

3

7

I'm currently using DatePicker’s control, where I tried to limit the dates to show MinDate & Maxdate. Unfortunately I couldn't find any related method to set the Min and Max days/Month except for Year, I even tried to extends the Controls class to set the Date to be display during it the DatePicker loaded. Is it possible to limit which dates a user can select from a datepicker on a UWP application?

Thanks!

Mafalda answered 15/9, 2015 at 3:20 Comment(0)
M
8

I assume you're developing on Windows 10 Universal Windows Platform. DatePicker in UWP, you can only set the MinYear and MaxYear. There's 4 datetime control that you can use (Refer to this link)

I would suggest you to use the new Calendar Date Picker which allows you to set MinDate and MaxDate

CalendarDatePicker cdp=new CalendarDatePicker();
cdp.MinYear=DateTime.Now();
cdp.MaxYear=DateTime.AddYears(3);
Moton answered 15/9, 2015 at 3:49 Comment(1)
There's not any property named MinYear and MaxYear in CalendarDatePicker.On
S
10

If you use DatePicker control (.net Framework >= 4.0) you can bind it also directly in the XAML code like this :


 <DatePicker
            x:Name="datePickr"
            MinWidth="150"
            Margin="10"
            DisplayDateEnd="{Binding Mode=OneWay, Source={x:Static
            System:DateTime.Today}}"/>

and if you use DateTimePicker control from Xceed Extended WPF toolkit you can bind Maximum Property the same way as DisplayDateEnd for DatePicker.

p.s. Don't forget to add folowing to your XAML file header:

xmlns:System="clr-namespace:System;assembly=mscorlib"
Sextillion answered 20/8, 2019 at 9:2 Comment(0)
M
8

I assume you're developing on Windows 10 Universal Windows Platform. DatePicker in UWP, you can only set the MinYear and MaxYear. There's 4 datetime control that you can use (Refer to this link)

I would suggest you to use the new Calendar Date Picker which allows you to set MinDate and MaxDate

CalendarDatePicker cdp=new CalendarDatePicker();
cdp.MinYear=DateTime.Now();
cdp.MaxYear=DateTime.AddYears(3);
Moton answered 15/9, 2015 at 3:49 Comment(1)
There's not any property named MinYear and MaxYear in CalendarDatePicker.On
T
3

WPF DatePicker has the DisplayDateStart and DislayDateEnd properties; see https://msdn.microsoft.com/en-us/library/system.windows.controls.datepicker.displaydatestart(v=vs.110).aspx.

Tonsil answered 15/9, 2015 at 3:53 Comment(1)
The question refers to winrt-xamlBoult

© 2022 - 2024 — McMap. All rights reserved.