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
我正在使用WPF工具包的Calendar控件来允许用户选择日期。如果尚未选择日期,则SelectedDate绑定的属性为Null。这使日历默认为1月1日,AD。我想做点什么
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?
但是“今天”和“现在”都会引发绑定错误。我可以使用TargetNullValue将默认日期设置为今天或现在吗?
1 个解决方案
#1
12
Try this:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
...
TargetNullValue={x:Static sys:DateTime.Now}
#1
12
Try this:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
...
TargetNullValue={x:Static sys:DateTime.Now}