I have a ScheduleView .xaml like this:
<Window>
...
<Grid>
<telerik:RadScheduleView AppointmentsSource="{Binding Appointments}"
<telerik:RadScheduleView.ViewDefinitions>
<telerik:DayViewDefinition/>
<telerik:WeekViewDefinition/>
<telerik:MonthViewDefinition/>
</telerik:RadScheduleView.ViewDefinitions>
</telerik:RadScheduleView>
</Grid>
</Window>
And every time I open the window, my ViewModel is loading the Appointments like this:
Appointments = new ObservableCollection<Appointment>();
private async Task CreateAppointments()
{
Appointments = await _service.GetAllAppointments();
}
While the _service retrieves the data from the server only once and saves it to memory as an ObservableCollection, and next time brings it just from memory.
The first time I opened the Schedule window, everything is working well.
But the next time I opened the Schedule window, I can see that the Week-view and the Day-view are looking the same. if I am trying to press the Day or Week buttons the view is jumping forth and back and stayed the same. (see pictures attached).
I notice that if I'm just changing my code to be like this: (no other changes)
private async Task CreateAppointments()
{
Appointments.AddRange(await _service.GetAllAppointments());
}
It makes the issue disappear and all is working well.
But I don't want to use AddRange because I need my UI to be bounded directly to the ObservableCollection from the _service so I can be notified on any collection changed by the _service side.
[update:]
After this, I found that if I set Appointments to null on the window close, all back to work well (without the need to use AddRange),
I just added to the code behind like this:
private void ScheduleWindowView_OnClosed(object sender, WindowClosedEventArgs e)
{
(DataContext as IDisposable)?.Dispose();
}
And I also added to my ViewModel this implementation:
protected override void Dispose(bool disposing){
Appointments = null;
}
I can live with this solution, but can anyone explain what exactly was the issue and how it was solved?