I'd like to bind a list of dates to the BlackoutDates property but it doesn't really seem to possible. Especially in a MVVM scenario. Has anyone accomplished something like this? Are there any good calendar controls that play nice with MVVM?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
I implemented the above example (the AttachedProperties class). I created a property in my Viewmodel like this:
This ViewModel inerits from ObservableBase:
This is the Xaml in the window that uses this property:
Now when I want to add BlackoutDates to the calendar, I call UpdateCalendarBlackoutDates in my ViewModel:
This works perfectly for me. It could be further perfected by changing the OnRegisterCommandBindingChanged method to accept a List of DateRanges instead of a CalendarBlackoutDatesCollection, and changing the property to a List like this:
but for now this works for me..
Here is an improved version of Matt's answer that allows us to work with the BlackoutDates as with any normal Observable collection (you don't need to create new collections each time you want to change the BlackoutDates). We store a list of all the calendars and datepickers binded and inside their tag we store the collection used in MVVM. An easy modification of the class will allow to work with ObservableCollection<DateTime> if needed:
Here is the ObservableCollection<DateTime> version:
For your DatePicker dilemma, I found a neat hack using attached properties (modified from my use of CommandBindings):
I'm sure I'm too late to help you out, but hopefully someone else will find it useful.