XamarinCommunityToolkit icon indicating copy to clipboard operation
XamarinCommunityToolkit copied to clipboard

[Bug] TabView Can't Be Added Or Removed After Created

Open albilaga opened this issue 4 years ago • 2 comments

Description

Steps to Reproduce

Remove TabViewItem:

  1. Create TabView in XAML with many TabViews (example TabViewItem1, TabViewItem2, TabViewItem3, TabViewItem4, TabViewItem5)
  2. Now when in OnAppearing try remove TabViewItem. Example TabView.TabViewItems.RemoveAt(2). It will remove TabViewItem3
  3. Now tab in the middle will be gone. Try select the tab next to it which is TabViewItem4

Add TabViewItem:

  1. Create TabView in XAML with many TabViews (example TabViewItem1, TabViewItem2, TabViewItem3, TabViewItem4, TabViewItem5)
  2. Now when in OnAppearing try 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 check TabView.SelectedIndex is set to 2 which should be correct and TabView.TabItems still 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 : image

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.

albilaga avatar Apr 21 '21 08:04 albilaga

Not sure if it's a bug or a known limitation. @jsuarezruiz could you tell us about it?

pictos avatar Apr 21 '21 23:04 pictos

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.'

eyeveye avatar Jul 07 '22 07:07 eyeveye