XamarinCommunityToolkit
XamarinCommunityToolkit copied to clipboard
[Bug] TabView Can't Be Added Or Removed After Created
Description
Steps to Reproduce
Remove TabViewItem:
- Create TabView in XAML with many TabViews (example TabViewItem1, TabViewItem2, TabViewItem3, TabViewItem4, TabViewItem5)
- Now when in
OnAppearingtry remove TabViewItem. ExampleTabView.TabViewItems.RemoveAt(2). It will removeTabViewItem3 - Now tab in the middle will be gone. Try select the tab next to it which is
TabViewItem4
Add TabViewItem:
- Create TabView in XAML with many TabViews (example TabViewItem1, TabViewItem2, TabViewItem3, TabViewItem4, TabViewItem5)
- Now when in
OnAppearingtry add TabViewItem. Example
TabView.TabViewItems.Add(new TabViewItem
{
Text="Tab 6",
Content = new ContentView()
});
It will add Tab 6 to the most right tabs. 3. Now try click Tab 6 which is the one tab that we just added
Expected Behavior
- For remove TabViewItem, the tabs should be resized after removed and clicking tab next to it not throwing
- For add TabViewItem, the tabs should be able to get clicked after added
Actual Behavior
- For remove TabViewItem, it will throw exception
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.I checkTabView.SelectedIndexis set to 2 which should be correct andTabView.TabItemsstill at 4 which also correct - For add TabViewItem, it will throw exception
System.IndexOutOfRangeException: Can't set CarouselView to position 5. ItemsSource has 5 items.
Basic Information
- Version with issue: v1.1.0
- Last known good version: -
- Platform Target Frameworks:
- iOS: Not tested
- Android: 11.0
- UWP: Not Tested
Reproduction imagery
Remove TabViewItem :

Reproduction Link
Can use this https://github.com/albilaga/XamarinIssues/tree/main/XamarinIssues/TabViews as base and then in here https://github.com/albilaga/XamarinIssues/blob/main/XamarinIssues/TabViews/MainTabPage.xaml.cs can add OnAppearing to remove or add TabViewItem.
Not sure if it's a bug or a known limitation. @jsuarezruiz could you tell us about it?
Yes, I encounter the exact issue. After deleting a tabviewitem, the rest of the tab doesn't resize and if you move to the tab that is deleted it throw the error - System.IndexOutOfRangeException: 'Can't set CarouselView to position 1. ItemsSource has 1 items.'