ScheduleView in TabControl: exception

5 posts, 1 answers
  1. Massimiliano Giustizieri
    Massimiliano Giustizieri avatar
    18 posts
    Member since:
    Oct 2009

    Posted 15 Jun 2011 Link to this post

    Dear Telerik Team,

    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 :
    1. remove the appointments to the ScheduleView
    2. add the ViewDefinition to the ScheduleView
    3. 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.

  2. Massimiliano Giustizieri
    Massimiliano Giustizieri avatar
    18 posts
    Member since:
    Oct 2009

    Posted 15 Jun 2011 Link to this post

    Alternatively, instead of creating and adding new views (which may be the action that directly or indirectly causes the problem), is there a way to customize the appearance of the ViewDefinitions buttons in the navigation bar ?

    This would probably help, because the ViewDefinitions could be moved from the attached properties handlers back to the XAML, and then the ViewDefinitions filtering mechanism would be implemented simply by hiding and showing the selected views (since ViewDefinitions don't seem to have a Visibility property).

    Thanks again!

    Regards,

    Massimiliano.
  3. DevCraft banner
  4. Answer
    Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 17 Jun 2011 Link to this post

    Hello Massimiliano,

    This error is caused by bug in the Silverlight Framework - we create CollectionView for the AppointmentsSource collection. Then when you switch to the first tab data context changed should be fired for the RadScheduleView and there we will remove handlers from this CollectionView. But the problem is that in SL we do not receive this event and cannot disconnect from the CollectionView. Then on second activation of RadTabItem which contains RadScheduleView it happened that a new instance of RadScheduleView is created and it tries to prepare the same CollectionView (group it) as the old RadScheduleView. This preparing raise CollectionView event that is also handled from the old ScheudleView which also tries to prepare the CollectionView and this cause an exception.
    We have contacted Microsoft about this problem and we are waiting for solution.
    Meanwhile you can set IsContentPreserved=True on RadTabControl to workaround the problem.

    All the best,
    Hristo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Xavier Lavigne
    Xavier Lavigne avatar
    2 posts
    Member since:
    Jul 2009

    Posted 23 Aug 2012 Link to this post

    Hi,

    Any news about this bug ? We've got the same problem using RadScheduleView in Lightswitch and we don't have any access to the tab's properties.

    Any workaround would also be appreciated.

    Thanks by advance.
  6. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 28 Aug 2012 Link to this post

    Hello Xavier,

    There haven't been any fixes released concerning this issue in Silverlight 4 and we can not provide you with any appropriate workarounds.

    There aren't any plans on implementing any work-arounds for this issue in the control because making those kind of changes are considered breaking changes and may lead to other unexpected issues.

    We are sorry for any inconvenience that this may be causing.

    Regards,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner