禁用日期晚于日期选择器窗口中的今天日期 Windows Phone 8



我正在使用Windows Phone 8工具包中的DatePicker,我想禁用比今天晚的日期。如何在我的自定义日期选取器中执行此操作?

不幸的是,使用默认的日期选择器无法做到这一点。您只能限制最小和最大年份。

根据上面的评论更新:

使用电话工具包时间选取器时,可以更改工具包的 *DateSource 类中的行为。下面是我添加最大日期的示例。从 GetRelativeTo(...) 返回 null 会破坏循环选择器,并在末尾停止。

    internal class DayDataSource : DataSource
    {
        protected override DateTime? GetRelativeTo(DateTime relativeDate, int delta)
        {
            var nextDay = relativeDate.AddDays(delta);
            if (nextDay.Date < DateTime.Now.Date || nextDay.Date > MaxValue.Date)
            {
                return null;
            }
            return new DateTime(relativeDate.Year, relativeDate.Month, nextDay.Day, relativeDate.Hour, relativeDate.Minute, 0);
        }
    }

您将不得不找出实现的更多细节,我记得我花了一些时间来完成它。

最新更新