如何设置TargetNullValue为一个日期? [英] How do I set TargetNullValue to a date?

查看:211
本文介绍了如何设置TargetNullValue为一个日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用WPF工具包的日历控件允许用户选择日期。如果尚未选择日期,则SelectedDate绑定的属性为Null。这使得日历默认为您的1月1日,0 AD。我想做一些像

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}"

但是Today和Now都会抛出绑定错误。我可以使用TargetNullValue将默认日期设置为Today或Now?

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

推荐答案

尝试:

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

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

这篇关于如何设置TargetNullValue为一个日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆