Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am using the below mentioned DatePicker control in my windows universal app.
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.controls.datepicker.aspx[^]

The date picker value is always defaulting to current day. I wanted to make it null, but it is somehow not working. DateOfBirth is the bound value which is of type DateTimeOffset
Below is the XAML part
C#
<DatePicker  
Visibility="{Binding DateOfBirth.Visibility}"
IsEnabled="{Binding DateOfBirth.EditEnabled}" 
Date="{Binding DateOfBirth.Value, Mode=TwoWay}" x:Name="myDatePicker"/>

In C# code:
Both of the below items are not working
1. In my View model where the DateOfBirth value is defined
C#
DateTimeOffset? nullableDate = null;
DateOfBirth = nullableDate;

This results in showing the MinDate value.
or
2. In the XAML code behind
C#
DateTimeOffset? nullableDate = null;
myDatePicker.Date = (DateTimeOffset)nullableDate;

This results in an InvalidOperation exception that nullableDate should have an value.

Any suggestions to make this null?

Thanks in advance
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900