Ragavan
Ragavan

Reputation: 3034

Prevent deselect date UWP Calendar Control

My application date is required , if i double click date in calender control , getting null Date , i want disable double click how to do that ? below i added my code

  <CalendarDatePicker
                        Name="calendarPicker"
                        Width="250"
                        Margin="30,10,10,10"
                        Date="{Binding Date, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"                     
                        MaxDate="{Binding MaxDateTime}"/>

Upvotes: 0

Views: 492

Answers (1)

jmshapland
jmshapland

Reputation: 483

I couldn't find a way to accomplish this via a property, but you can accomplish this by adding an event handler on the DateChanged event. You'll want to make sure you have a default value or value assigned to the CalendarDatePicker to start off or this may cause problems.

  <CalendarDatePicker
                        Name="calendarPicker"
                        Width="250"
                        Margin="30,10,10,10"
                        Date="{Binding Date, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"                     
                        MaxDate="{Binding MaxDateTime}"
                        DateChanged="DatePicker_DateChanged"/>

and then adding this in the code behind for the XAML page:

private void DatePicker_DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
    if (!sender.Date.HasValue) sender.Date = args.OldDate;
}

Upvotes: 1

Related Questions