Question

I'm using the WPF toolkit's Calendar control to allow users to select a date. If the date is not yet selected then the property the SelectedDate is bound to is Null. This makes the Calendar default you January 1, 0 AD. I'd like to do something like

SelectedDate="{Binding UserPickedDate, TargetNullValue=Today, Mode=TwoWay}"

But both "Today" and "Now" throw binding errors. Can I use TargetNullValue to set the default date to Today or Now?

Was it helpful?

Solution

Try this:

xmlns:sys="clr-namespace:System;assembly=mscorlib"
...

TargetNullValue={x:Static sys:DateTime.Now}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top