in our product we make extensive use of the ScheduleView. All of them work fine, except one that has a slightly different configuration.
It is located in a UserControl that includes one TabControl with two tabs. In the first tab there is a form with some other controls, in the second one there is the ScheduleView control that shows the same data from the form in the first tab.
The ScheduleView is configured with 4 boolean attached properties (called IsDay.., IsMonth... , IsWeek... and IsTimlineViewAllowed) that determine if the related ViewDefinition will be available in the ScheduleView. These attached properties are of course bound from properties in the view model.
The ScheduleView control has got no ViewDefinitions hardcoded in the XAML, because each ViewDefinition is dinamically created by the related change event handler of the attached property. Here you can see one of them (the one for the month, just to give an example), it does a really simple job:
private
static
void
OnIsMonthViewAllowedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
RadScheduleView scheduler = obj
as
RadScheduleView;
bool
allowed = Convert.ToBoolean(args.NewValue.ToString());
ViewDefinitionBase monthView =
null
;
if
(allowed && scheduler !=
null
)
{
monthView =
new
MonthViewDefinition() { StretchGroupHeaders =
true
};
scheduler.ViewDefinitions.Add(monthView);
}
}
This similar configuration works fine in all other ScheduleView controls of the product, but in this case the statement
scheduler.ViewDefinitions.Add(monthView);
throws the exception exception "Cannot change ObservableCollection during a CollectionChanged or PropertyChanged event." when switching from the first to second tab.
I have a suspect that this is something related to the collection of appointments or something else, and in fact I did an "experiment" and if I try to :
- remove the appointments to the ScheduleView
- add the ViewDefinition to the ScheduleView
- re-populate the datasource of appointments
It does not throw the exception and the ScheduleView appears as expected with all its appointments.
However this is not the ideal approach as this is a very ugly design. Even if it is kinda working we eventually should need to re-configure in this way all the aspects of the ScheduleView (we use resource grouping, we use resource headers, we use a lot of things that really descourages the use of this experimental tecnique).
Do you know if there's a reason that is causing this behaviour? It would be great if you could suggest a way to avoid the problem, or even a tip to improve our design (meaning avoid using attached properties, or avoid adding ViewDefinitions at run-time in this way).
Thank you very much!
Kind Regards,
Massimiliano Giustizieri, Italy.
------------------------------------------------------------------------------------------
Edit: The behaviour is exactly as described in this other post http://www.telerik.com/community/forums/silverlight/scheduleview/scheduleview-in-radtabcontrol-throws-error-when-tab-re-activated.aspx, meaning that it happens only the second time the TabControl with the ScheuleView is activated.