An open API service indexing awesome lists of open source software.

https://github.com/syncfusionexamples/how-to-create-equal-width-tab-items-with-horizontal-scrolling-in-.net-maui-tabview

This repository contains a sample explaining how to create equal-width tab items and enable horizontal scrolling in the .NET MAUI TabView.
https://github.com/syncfusionexamples/how-to-create-equal-width-tab-items-with-horizontal-scrolling-in-.net-maui-tabview

customization header-item-template maui maui--tab-view scroll-view tab-view

Last synced: 2 months ago
JSON representation

This repository contains a sample explaining how to create equal-width tab items and enable horizontal scrolling in the .NET MAUI TabView.

Awesome Lists containing this project

README

        

In this article, you can learn about how to create equal-width tab items and enable horizontal scrolling to access items that exceed the visible area in the [.NET MAUI TabView](https://www.syncfusion.com/maui-controls/maui-tab-view). This can be achieved by customizing the [HeaderItemTemplate](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.TabView.SfTabView.html#Syncfusion_Maui_TabView_SfTabView_HeaderItemTemplate) in the TabView.

To create a TabView with equal width for all tab items and enable horizontal scrolling, follow these steps:

1. **Define the TabView**: Start by defining the `TabView` in your XAML.
2. **Set the HeaderItemTemplate**: Use the `HeaderItemTemplate` to specify how each tab item should be displayed. This template will allow you to set a common width for all tab items and enable horizontal scrolling when the number of items exceeds the visible area.

Here is an example of how to implement this:

**Model**

```
public class Model
{
public string? Name { get; set; }
}
```

**ViewModel**

```
public class ViewModel : INotifyPropertyChanged
{
private ObservableCollection? tabHeaderCollection;
public ObservableCollection? TabHeaderCollection
{
get { return tabHeaderCollection; }
set { tabHeaderCollection = value;
OnPropertyChanged(nameof(TabHeaderCollection)); }

}
...
public ViewModel()
{
TabHeaderCollection = new ObservableCollection()
{
new Model(){Name = "Call"},
new Model(){Name = "Favourite"},
new Model(){Name = "Contacts"},
new Model(){Name = "More"},
new Model(){Name = "Help"},
new Model(){Name = "Info" },
new Model(){Name = "About"},
new Model(){Name = "Settings"},
};
}
}
```

**XAML**

```xml















```

By following the above steps, you can create a Syncfusion TabView with equal-width tab items and horizontal scrolling functionality. This enhances the user experience by allowing easy navigation through multiple tabs.

**Output**

![TabViewHeaderItemTemplate.gif](https://support.syncfusion.com/kb/agent/attachment/article/17124/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjI4Mjg2Iiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.GnslrkdN_fVV4kltZeHrdbBI4j89xini2wCusbCmmC8)