enisn / UraniumUI

Uranium is a Free & Open-Source UI Kit for MAUI.
Apache License 2.0
982 stars 110 forks source link

Remove Tab Items in runtime #626

Closed MohammedDastagir closed 1 month ago

MohammedDastagir commented 1 month ago

I'm using Uranium tabsview control and I have a feature to remove tab at runtime based on a condition. I tried below code

In my xaml :

  <material:TabView x:Name="tabsView">
       <material:TabItem Title="{StaticResource Icons.AttributeQuery}" HeaderTemplate="{StaticResource TabTemplate}">
           <material:TabItem.Content>
               <dataAnalysis:AttributeQueryListView x:Name="attributeQueryListView"/>
           </material:TabItem.Content>
       </material:TabItem>
  </material:TabView>

and in my xaml.cs:

     tabsView.RemoveAt(0);
     tabsView.Children.RemoveAt(0)

I found only above two methods but it's not working. Is there any solution to this.

Any help is appreciated, thanks!

enisn commented 1 month ago

Normally TabView supports binding items like

<m:TabView ItemsSource="{Binding MyItems}"  />
<!-- or -->
<m:TabView Items="{Binding MyTabItems}"  />

When you add or remove items from collection, it automatically affects to TabView.

But still, you can remove them manually from C# code. Try the following way:

        tabView.Items.Remove(tabView.Items[0]);
MohammedDastagir commented 1 month ago

@enisn Thanks for your response. Your solution worked like a charm.