在 WPF/xaml 中设置静态日期时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16463217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:45:37  来源:igfitidea点击:

Setting a static datetime in WPF/xaml

c#wpf

提问by Mike

I'm trying to blackout dates in my datetime picker control starting from day after today till datetime max value.

我试图在我的日期时间选择器控件中从后天开始直到日期时间最大值停止日期。

The below is the code:

下面是代码:

    <Calendar.BlackoutDates>
        <CalendarDateRange Start="{x:Static System:DateTime.Today}"
 End="{x:Static System:DateTime.MaxValue}" />
    </Calendar.BlackoutDates>

As you could see, the above code will blackout dates starting from today, but I want the start date from tomorrow. Basically the question is, how can I set something like this:

如您所见,上面的代码将从今天开始取消日期,但我想要从明天开始的日期。基本上问题是,我如何设置这样的东西:

Start="{x:Static System:DateTime.Today.AddDays(1)}"

Start="{x:Static System:DateTime.Today.AddDays(1)}"

Could you please help?

能否请你帮忙?

回答by Jay

You can create your own static property for this.

您可以为此创建自己的静态属性。

  public static class DateTimeHelper
  {
    public static DateTime Tomorrow
    {
      get { return DateTime.Today.AddDays(1); }
    }
  }

.

.

  <CalendarDateRange Start="{x:Static app:DateTimeHelper.Tomorrow}"…