TabControl Duplicating Tabs

2 posts, 0 answers
  1. digitall
    digitall avatar
    169 posts
    Member since:
    Jun 2006

    Posted 30 Jul 2011 Link to this post

    I am using the MVVM pattern (with MVVM light) and have a Telerik TabControl bound to a collection of ViewModels like this:

    <telerik:RadTabControl x:Name="tabs" telerik:Theming.Theme="Windows7" BackgroundVisibility="Collapsed" TabStripPlacement="Left" TabOrientation="Vertical" DisplayMemberPath="Name" IsContentPreserved="True"
                                               ItemsSource="{Binding ReviewViewModels, UpdateSourceTrigger=PropertyChanged}" ContentTemplateSelector="{StaticResource ReviewTemplateSelector}" Align="Right"
                                               ItemContainerStyle="{StaticResource ReviewCategoryTabStyle}" SelectedIndex="{Binding SelectedIndex}" />

    The ReviewViewModels collection is an ObservableCollection<object> because I have one static tab along with any number (generally 2-3) of user-selected tabs based on items selected in another window. Since the ViewModels are drastically different I had to be as generic as possible for the root collection and then use a ContentTemplateSelector to show the appropriate content.

    The issue I have is occasionally one of the tabs is duplicated, even though the underlying source doesn't reflect this. It's very intermittent, but I just happened to catch it on my screen while working on something with the app (Phase I is still in development) and the screen showed four tabs (one was a duplicate) and when I hit a button on the view to catch in a breakpoint I could see the underlying collection only contained three total items (which was expected). I can't seem to figure out where this other item is coming from as when data retrieval is complete for the tab content I explicitely instantiate the collection at that time and loop through to add the items like this:
    Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Send, new Action(() =>
                    this.ReviewViewModels = new ObservableRangeCollection<object>();
                    //add the categories - this is the only place the items are added
                    foreach (var cat in this.ReviewCategories)
                        this.ReviewViewModels.Add(new ReviewCategoryViewModel(cat));
                    //add a new notes viewmodel
                    this.ReviewViewModels.Add(new ReviewNotesViewModel());
                    //collection size shows three entries (two ReviewCategoryViewModel and one ReviewNotesViewModel), tabs occasionally show four at this point
                    this.SelectedIndex = 0;
                    this.IsBusy = false;

    Any suggestions on this as to where to even start looking? I am using Q2 2011.

    Edit: It just happened again and the interesting thing is the fourth tab (the duplicate) is selected even though (as indicated above) I set the selected index to 0. I hit a button on the view that takes me to the VM and did a couple of screenshots showing the data is correct: (Immediate Window - shows three total ViewModels [expected] and SelectedIndex is 0) (UI of the duplicate tab, with the fourth being selected even though SelectedIndex is 0 and only three ViewModels exist).

    Again, this is VERY interimmittent and reproducing it is intentionally possible. It just happens occasionally.
  2. Vladislav
    Vladislav avatar
    274 posts

    Posted 03 Aug 2011 Link to this post

    Hi Digitall,

    Unfortunately the information provided is not enough in order to reproduce and identify the problem.
    Can we ask you to send us a sample project demonstrating the issue?

    Thank you in advance for your cooperation.

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. DevCraft R3 2016 release webinar banner
Back to Top