Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set TargetNullValue to a date?

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?

like image 581
Bryan Anderson Avatar asked Feb 05 '09 17:02

Bryan Anderson


1 Answers

Try this:

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

TargetNullValue={x:Static sys:DateTime.Now}
like image 121
rudigrobler Avatar answered Nov 15 '22 08:11

rudigrobler