如何将日期选择器的值绑定到不可为空的属性时将其设置为null? [英] How di I set the value of a date picker to be null when it's bound to a non-nullable property?

查看:91
本文介绍了如何将日期选择器的值绑定到不可为空的属性时将其设置为null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有一个Patient实体,它包含几个日期属性,例如DateOfBirth和AccidentDate.这些是非空属性,因为它们是必需的,但是,当添加新患者时,我不希望这些属性自动填充, 就像默认情况下一样,因为用户很可能会忘记更改它们.

I have a Patient entity, and this contains a couple of date properties, such as DateOfBirth and AccidentDate. These are non-nullable properties, as they are required, however, when a new patient is added, I don't want these properties populating automatically, as they are by default, as the user is very likely to forget to change them.

如何清除这些值?我尝试获取日期选择器控件并将SelectedDate属性设置为null,但屏幕上的控件仍显示当前日期.我无法将实体的日期设置为null,因为它不可为空.

How can I blank out the values? I tried getting the date picker controls and setting the SelectedDate property to null, but the control on the screen still showed the current date. I can't set the entity's date to null as it's not nullable.

有人有什么想法吗?谢谢

Anyone any ideas? Thanks

Lightswitch的免费自定义控件!对Lightswitch开发人员的有用控件的集合. 从Visual Studio库中下载.

FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

如果您真的很无聊,可以在以下位置阅读有关使用.NET和Microsoft某些较新技术的实验的信息 http://dotnetwhatnot.pixata.co.uk/

If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

推荐答案

我没有针对您的特定问题的答案,但是有一些潜在的解决方法.如果您有权访问数据库,请将列设置为可空,然后使用LS验证来强制属性具有值,然后再进行记录 被保存.如果您不能或不想更改数据库,请将其默认设置为当前日期,如果值是当前日期,即用户忘记更改它,请使用LS验证来指出错误.理解这不如设定 必填字段为null,但我不知道有什么方法可以做到这一点.最后,您可以设置datetime = DateTime.MinValue吗?
I don't have an answer for your specific question but there are some potential workarounds.  If you have access to the database, make the columns nullable, and use LS validation to enforce that the properties have a value before the record can be saved.  If you can't or don't want to change the database, leave them default to the current date and use LS validation to error out if the value is the current date, i.e. the user forgot to change it.  Understood that this is not as good as setting the required fields to null, but I don't know of any way to do that.  Finally, can you set the datetime = DateTime.MinValue?


这篇关于如何将日期选择器的值绑定到不可为空的属性时将其设置为null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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