We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SfTabControl and ItemsSource/Data binding

I am trying to use data-binding for creating a SFTabControl on the MainPage using the code provided in one of the help pages of syncfusion for sftabcontrol (https://help.syncfusion.com/uwp/sftabcontrol/populating-items).
However, I am getting a blank page (and not tabs created)

Following is my code:

<Page
    x:Class="Man.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Man"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:syncfusion="using:Syncfusion.UI.Xaml.Grid"
    xmlns:navigation="using:Syncfusion.UI.Xaml.Controls.Navigation"    
    RequestedTheme="Dark"
    mc:Ignorable="d">
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Grid.RowDefinitions>
                <RowDefinition Height="1*"/>                
            </Grid.RowDefinitions>
            <navigation:SfTabControl Grid.Row="0" ItemsSource="{Binding Employees}"/>


    </Grid>
</Page>


namespace Man
{
    public class Employee 

    {

        public string Name { get; set; }

        public string Description { get; set; }

        
    }
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {

        private List<Employee> employees;

        public List<Employee> Employees

        {

            get { return employees; }

            set { employees = value; }

        }

        public MainPage()
        {
            this.InitializeComponent();

            Employees = new List<Employee>();

            Employees.Add(new Employee() { Name = "James", Description = "Description about James" });

            Employees.Add(new Employee() { Name = "Linda", Description = "Description about Linda" });

            Employees.Add(new Employee() { Name = "Carl", Description = "Description about Carl" });

            Employees.Add(new Employee() { Name = "Niko", Description = "Description about Niko" });

        }        
    }
}


Can anyone tell me whats wrong with the code. 

Also, I am not sure how this approach is supposed to work considering that there is no ObservableCollection implemented.

Is there a simpler working example for using ItemsSource/data-binding with SfTabControl

2 Replies

AM Achint Mehta December 29, 2016 04:15 PM UTC

Apparently I figured out that replacing <navigation:SfTabControl Grid.Row="0" ItemsSource="{Binding Employees}"/> with <navigation:SfTabControl Grid.Row="0" ItemsSource="{x:Bind Employees, Mode=OneWay}"/> works to some extent.

Now if the Source List (Employees) is populated in the MainPage constructor then tabs are created but if Source List is populated in Loaded event of the page then there are not tabs created. This happens even if the Source List is defined as ObservableCollection


MS Marimuthu Sivalingam Syncfusion Team January 2, 2017 09:59 AM UTC

Hi Achint,

Thank you for contacting Syncfusion support.

We suspect that you have missed to set DataContext, so that control could not get information about data source used in binding. We have prepared a sample to demonstrate creating SfTabControl items through binding and you can download it from the following link:

Sample: 128055_SfTabControlBinding

Regards,
Marimuthu S.

Loader.
Up arrow icon