How to get property element in list header content in sftabitem

I create list header content in view model
Tabitems = new TabItemCollection();
foreach (var itemRss in RssItems)
                    {
                        var NamePath = itemRss.Substring(8);
                        int index = NamePath.IndexOf('.');
                        if (index > 0)
                        {
                            var pieces = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(NamePath.Substring(0, index).ToLower());
                            TabItemContents content = new TabItemContents(itemRss);
                            TabItemHeaders headers = new TabItemHeaders(pieces, ColorItems.GetValue(i).ToString());
                            tabItem = new SfTabItem
                            {
                                HeaderContent = headers.Content,
                                Content = content.Content,
                                FontIconFontFamily = "Arial",
                                FontIconFontSize = 100
                            };
                            i += 1;
                            Tabitems.Add(tabItem);
                        }
                    }
header content is content page
<ContentPage.Content>
        <StackLayout>
            <yummy:PancakeView CornerRadius="4,4,0,0" BackgroundColor="{Binding Source={x:Reference lbl}, Path=BackgroundColor}"
                               Margin="{Binding MarginPancake}"
                               Padding="0,0,0,-5">
                <StackLayout HorizontalOptions="FillAndExpand">
                    <Label x:Name="lbl" 
                        Margin="0,5,0,0"
                       TextColor="White"
                       FontFamily="{DynamicResource labelStyleFont}"
                       Text="{Binding btnTitle}" 
                       BackgroundColor="{Binding btnColor}"
                       VerticalOptions="Center" 
                       HorizontalOptions="Center" >
                    </Label>
                    <StackLayout Padding="{Binding PaddingStack}"  BackgroundColor="{Binding StackColor}"/>
                </StackLayout>
            </yummy:PancakeView>
        </StackLayout>
    </ContentPage.Content>
I want to check each header in the list and get the PancakeView margin inside the header through the selectedchanged event, my purpose is to change the PancakeView margin when I click on it, currently it is changing the entire margin which is not the I am clicking on. Thanks

1 Reply

SP Sakthivel Palaniyappan Syncfusion Team May 1, 2020 08:46 AM UTC

Hi TruongCP,

Greetings from Syncfusion.

We have analyzed your query and you can achieve your requirement as like below code snippet.

XAML:

 
<SftabView:SfTabView x:Name="theTabView"  VerticalOptions="FillAndExpand" SelectionChanged="TabView_SelectionChanged" 
                             Margin="0,0,0,0" 
                             Grid.Row="0" SelectedIndex="{Binding SelectedIndex,Mode=TwoWay}" 
                             BackgroundColor="White" 
                             IsScrollButtonEnabled="False" 
                             OverflowMode="Scroll" 
                             Items="{Binding Tabitems}"> 
    </SftabView:SfTabView> 

C#:

 
  private void TheTabView_SelectionChanged(object sender, Syncfusion.XForms.TabView.SelectionChangedEventArgs e) 
        { 
            TabItemCollection tabItems = (sender as SfTabView).Items; 
 
            foreach (var item in tabItems) 
            { 
                int selectedIndex = tabItems.IndexOf(item); 
 
                if (selectedIndex == e.Index) 
                    ((item.HeaderContent as StackLayout).Children[0] as PanCakeView).Margin = 5; 
                else 
                    ((item.HeaderContent as StackLayout).Children[0] as PanCakeView).Margin = 0; 
            } 
        } 

We have modified the sample, please find the sample from below.

Sample:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/TabViewSample-2067548386.zip

Please let us know if you have any other queries.

Regards,
Sakthivel P.


Loader.
Up arrow icon