This is a migrated thread and some comments may be shown as answers.

TabControl Duplicating Tabs

1 Answer 208 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
digitall
Top achievements
Rank 1
digitall asked on 31 Jul 2011, 02:44 AM
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:

http://www.clearsolgroup.com/images/immediate-window.png (Immediate Window - shows three total ViewModels [expected] and SelectedIndex is 0)

http://www.clearsolgroup.com/images/duplicate-tab.png (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.

1 Answer, 1 is accepted

Sort by
0
Vladislav
Telerik team
answered on 03 Aug 2011, 01:53 PM
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,
Vladislav
the Telerik team

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

Tags
TabControl
Asked by
digitall
Top achievements
Rank 1
Answers by
Vladislav
Telerik team
Share this question
or