简体   繁体   中英

How to Set BlackOutDates for Multiple Months in WPF DateTimePick

I need to set BlackOutDates for multiple months.

For example, upon selection of month ( ie January 2014 ) , I want to show only certain Blackout dates. on the otherhand, For febraury, I want to show some other black out dates those were not the same as January.

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.

Is there any way, to set explicit BlackOutDays for each month.

Regards Usman

It is not possible to directly bind the BlackOutDates collection. 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. A detail explanation is given in below link.

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

To get notification from date picker when Month is changed, use DisplayDate property. 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)) };
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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