<tabView:SfTabView x:Name="tabView"
SelectionChanged="TabView_SelectionChanged"
VisibleHeaderCount="6">
<tabView:SfTabItem Title="Bar"/>
<tabView:SfTabItem Title="Line"/>
<tabView:SfTabItem Title="PieChart"/>
<tabView:SfTabItem Title="Doughnut"/>
<tabView:SfTabItem Title="Column"/>
<tabView:SfTabItem Title="Bar"/>
</tabView:SfTabView> |
public MainPage()
{
InitializeComponent();
if (tabView.Items[tabView.SelectedIndex].Content==null)
{
tabView.Items[tabView.SelectedIndex].Content = GetItemContent(tabView.SelectedIndex);
}
} |
private void TabView_SelectionChanged(object sender, Syncfusion.XForms.TabView.SelectionChangedEventArgs e)
{
if (tabView.Items[e.Index].Content == null)
{
tabView.Items[e.Index].Content = GetItemContent(e.Index);
}
}
private View GetItemContent(int index)
{
switch (index)
{
case 0:
return new BarChartPage().Content;
case 1:
return new LineSeriesPage().Content;
case 2:
return new PieChartPage().Content;
case 3:
return new DoughnutChart().Content;
case 4:
return new ColumnChart().Content;
case 5:
return new LineSeriesPage().Content;
default:
return new BarChartPage().Content;
}
} |
Hi Benjamin,Greetings from Syncfusion,We have analyzed your query and we have created sample based on this. Please find the sample link from below location.Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/TabViewScroll-911764712.zipIn this sample we have done the following things.1. Created TabItems without adding TabItem content and set TabItem content with the SelectedIndex as like below code snippet.
<tabView:SfTabView x:Name="tabView"SelectionChanged="TabView_SelectionChanged"VisibleHeaderCount="6"><tabView:SfTabItem Title="Bar"/><tabView:SfTabItem Title="Line"/><tabView:SfTabItem Title="PieChart"/><tabView:SfTabItem Title="Doughnut"/><tabView:SfTabItem Title="Column"/><tabView:SfTabItem Title="Bar"/></tabView:SfTabView>
public MainPage(){InitializeComponent();if (tabView.Items[tabView.SelectedIndex].Content==null){tabView.Items[tabView.SelectedIndex].Content = GetItemContent(tabView.SelectedIndex);}}2. When Tab on the next Item, get the item using SelectionChangedEvent and set the Content if the content is empty as like below code snippet.
private void TabView_SelectionChanged(object sender, Syncfusion.XForms.TabView.SelectionChangedEventArgs e){if (tabView.Items[e.Index].Content == null){tabView.Items[e.Index].Content = GetItemContent(e.Index);}}private View GetItemContent(int index){switch (index){case 0:return new BarChartPage().Content;case 1:return new LineSeriesPage().Content;case 2:return new PieChartPage().Content;case 3:return new DoughnutChart().Content;case 4:return new ColumnChart().Content;case 5:return new LineSeriesPage().Content;default:return new BarChartPage().Content;}}Please let us know if you have any concern.Thanks,Muneesh Kumar G
private void tabView_TabItemTapped(object sender, TabItemTappedEventArgs e)
{
var tabIndex = tabView.Items.IndexOf(e.TabItem);
if (tabView.Items[tabIndex].Content == null)
{
tabView.Items[tabIndex].Content = GetItemContent(tabIndex);
}
} |
<tabView:SfTabView EnableVirtualization="True"
x:Name="tabView" TabItemTapped="tabView_TabItemTapped"
DisplayMode="Text"
SelectedIndex="1"
BackgroundColor="White"
SelectionChanged="tabView_SelectionChanged"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<tabView:SfTabItem Title="Mail" x:Name="tabitem1">
<tabView:SfTabItem.Content>
<StackLayout x:Name="AllContactsGrid" BackgroundColor="AliceBlue" >
</StackLayout>
</tabView:SfTabItem.Content>
</tabView:SfTabItem>
…
<tabView:SfTabItem Title="Contacts" x:Name="tabitem4">
<tabView:SfTabItem.Content>
<StackLayout BackgroundColor="LightBlue" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
<Label Text="Page 4" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
</StackLayout>
</tabView:SfTabItem.Content>
</tabView:SfTabItem>
</tabView:SfTabView> |
void tabView_TabItemTapped(System.Object sender, Syncfusion.XForms.TabView.TabItemTappedEventArgs e)
{
bool isItemSelected = e.TabItem.IsSelected;
} |