简体   繁体   English

如何在WPF DateTimePick中为多个月设置BlackOutDates

[英]How to Set BlackOutDates for Multiple Months in WPF DateTimePick

I need to set BlackOutDates for multiple months. 我需要将BlackOutDates设置多个月。

For example, upon selection of month ( ie January 2014 ) , I want to show only certain Blackout dates. 例如,选择月份(即2014年1月)时,我只想显示某些停电日期。 on the otherhand, For febraury, I want to show some other black out dates those were not the same as January. 另一方面,对于febraury,我想显示其他与1月不同的日期。

But I can't find any property in WPF DateTimePick which can explicitly returns "months" those were bound to DateTimePick control at the time of List binding using ViewModel. 但是我在WPF DateTimePick中找不到可以显式返回在使用ViewModel进行列表绑定时绑定到DateTimePick控件的“月”的任何属性。

Is there any way, to set explicit BlackOutDays for each month. 有没有办法为每个月设置明确的BlackOutDays。

Regards Usman 问候乌斯曼

It is not possible to directly bind the BlackOutDates collection. 无法直接绑定BlackOutDates集合。 Instead a helper class will do the magic. 相反,辅助类将发挥作用。 Usually attached properties will be used to handle this scenario. 通常将使用附加的属性来处理这种情况。 In the callback of property do manual mapping of BlackoutDates. 在属性的回调中,执行BlackoutDates的手动映射。 A detail explanation is given in below link. 下面的链接中给出了详细说明。

http://wpfplayground.com/2014/07/28/wpf-datepicker-blackoutdates-data-binding/ http://wpfplayground.com/2014/07/28/wpf-datepicker-blackoutdates-data-binding/

To get notification from date picker when Month is changed, use DisplayDate property. 要在更改月份时从日期选择器获取通知,请使用DisplayDate属性。 Bind this property in two way. 用两种方式绑定此属性。 And you can update your black out date collection on property changed. 您还可以在更改的属性上更新停电日期集合。

    private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "DisplayDate")
        {
            BlackOutDates = new List<DateTime> { DisplayDate.Date.AddDays(randm.Next(1, 5)), DisplayDate.AddDays(randm.Next(1, 5)) };
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM