How to load the Listview within Tabview in Xamarin.Forms (SfListView)?
Load the SfListView inside the SfTabView in Xamarin.Forms ListView.
XAML
Define the SfListView in a separate XAML.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:local="clr-namespace:ListViewXamarin" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:sync="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms" x:Class="TabViewSample.BookPage"> <ContentPage.BindingContext> <local:BookInfoRepository /> </ContentPage.BindingContext> <sync:SfListView x:Name="listView" ItemsSource="{Binding BookInfo}" ItemSize="100"> <sync:SfListView.ItemTemplate> <DataTemplate> <Grid Padding="10"> <Grid.RowDefinitions> <RowDefinition Height="0.4*" /> <RowDefinition Height="0.6*" /> </Grid.RowDefinitions> <Label x:Name="label" Text="{Binding BookName}" FontSize="21" FontAttributes="Bold" /> <Label Grid.Row="1" Text="{Binding BookDescription}" FontSize="15" /> </Grid> </DataTemplate> </sync:SfListView.ItemTemplate> </sync:SfListView> </ContentPage>
XAML
Load the SfTabView in the MainPage.xaml.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:ListViewXamarin" xmlns:tabView="clr-namespace:Syncfusion.XForms.TabView;assembly=Syncfusion.SfTabView.XForms" x:Class="ListViewXamarin.MainPage"> <ContentPage.Content> <tabView:SfTabView VisibleHeaderCount="3" TabHeaderBackgroundColor="#dddddd"> <tabView:SfTabView.Behaviors> <local:SfTabViewBehavior/> </tabView:SfTabView.Behaviors> </tabView:SfTabView> </ContentPage.Content> </ContentPage>
C#
Create ListView page instance and add it to the SfTabView.Items collection.
public class SfTabViewBehavior : Behavior<SfTabView> { protected override void OnAttachedTo(SfTabView bindable) { BookPage bookPage = new BookPage(); InboxPage inboxPage = new InboxPage(); ContactPage contactPage = new ContactPage(); bindable.Items.Add(new SfTabItem { Content = bookPage.Content, Title = "Books" }); bindable.Items.Add(new SfTabItem { Content = inboxPage.Content, Title = "Inbox" }); bindable.Items.Add(new SfTabItem { Content = contactPage.Content, Title = "Contacts" }); base.OnAttachedTo(bindable); } }
Conclusion
I hope you enjoyed learning about how to load the Listview within Tabview in Xamarin.Forms (SfListView).
You can refer to our Xamarin.Forms ListView feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!