0

I have a calendar defined like so:

<Calendar Name="calendarA" SelectionMode="MultipleRange"/>

and a list box which displays the selected dates on the calendar:

<ListBox x:Name="dateListBox" ItemSource="{Binding ElementName=calendarA, Path=SelectedDates}" SelectionMode="Extended"/>

Now, this is all on the view, what I'd like to do is to somehow copy the selected dates either from the calendar or from the listbox to a property or ObservableCollection in my viewmodel, but I'm a little lost, how do I go about this? I didn't want to use code-behind

Slava
  • 73
  • 5
  • https://stackoverflow.com/a/3667609/1506454 – ASh Nov 16 '22 at 14:36
  • If you don't "want to use code-behind", then implement an attached behaviour. The solution is roughly the same anyway. You need to add the selected dates to the source collection yourself. – mm8 Nov 16 '22 at 14:54
  • Do `CalendarA` and `dateListBox` share the same datacontext/viewmodel? If so, can't you add an ObservableCollection property to the viewmodel and bind the `SelectedDates` and the `ItemsSource` to it? – Jürgen Röhr Nov 16 '22 at 20:28
  • @JürgenRöhr i don't think there's a CalendarDate data type, – Slava Nov 17 '22 at 17:25
  • 1
    @Slava According to your code a property of `SelectedDates` exists on the calendar. Take whatever class such a `SelectedDate` is made of and use it instead of `CalendarDate`. – Jürgen Röhr Nov 17 '22 at 19:04

0 Answers0