How do I set TargetNullValue to a date?

妖精的绣舞 提交于 2019-12-10 13:52:44

问题


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?


回答1:


Try this:

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

TargetNullValue={x:Static sys:DateTime.Now}


来源:https://stackoverflow.com/questions/517039/how-do-i-set-targetnullvalue-to-a-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!