如何将默认值DateTime设置为空字符串? [英] How to set the default value of DateTime to empty string?

查看:879
本文介绍了如何将默认值DateTime设置为空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Raised_Time的属性,此属性显示在datagrid Cell中引发警报的时间。当用户创建任何闹钟时,我不想在datagrid单元格中显示任何内容,只显示空单元格。



我在互联网上上网,发现默认DateTime的值可以使用DateTime.MinValue设置,这将显示datetime i:e1/1/0001 12:00:00 AM的MinValue。



相反,我希望数据网格单元格保持空白,直到报警提示,它不会显示任何时间。



<我认为datatrigger可以写在这种情况下。我无法为此方案编写datatrigger。我需要一个转换器,检查DateTime是否设置为DateTime.MinValue离开datagrid单元格空白?



请帮助!!

解决方案

如何更改您的财产以链接到DateTime的私人字段例如:

  public string Raised_Time 
{
get
{
if(fieldRaisedTime == DateTime.MinValue)
{
return string .Empty();
}
return DateTime.ToString();
}
set
{
fieldRaisedTime = DateTime.Parse(value,System.Globalization.CultureInfo.InvariantCulture);
}
}


I have a property called Raised_Time, this property shows the time at which alarm is raised in datagrid Cell. I don't want to show anything in the datagrid cell when user creates any alarm, it just display the empty cell.

I googled in the internet and found that the default value of DateTime can be set using DateTime.MinValue and this will display MinValue of datetime i:e "1/1/0001 12:00:00 AM".

Instead I want that the datagrid cell remain blank until alarm is raised, it don't show any time.

I think datatrigger can be written in this case. I am not able to write the datatrigger for this scenario. Do I need a converter also that checks if DateTime is set to DateTime.MinValue the leave the datagrid cell blank??

Please help!!

解决方案

How about just changing your property to link to a private field of DateTime e.g.:

public string Raised_Time
{
  get
  {
    if(fieldRaisedTime == DateTime.MinValue)
    {
      return string.Empty();
    }
    return DateTime.ToString();
  }
  set
  {
    fieldRaisedTime = DateTime.Parse(value,   System.Globalization.CultureInfo.InvariantCulture);
  }
}

这篇关于如何将默认值DateTime设置为空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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