Git Product home page Git Product logo

group-header-color-on-tap-listview-xamarin's Introduction

How to change the group header color on tap in Xamarin.Forms ListView (SfListView)

You can change the background color of group header of SfListview at runtime with the help of converter.

You can also refer the following article.

https://www.syncfusion.com/kb/11952/how-to-change-the-group-header-color-on-tap-in-xamarin-forms-listview-sflistview

C#

Converter returns the background color for the group header based on group items.

public class GroupHeaderConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null)
            return Color.Yellow;
        var items = (value as GroupResult).Items.ToList<Contacts>().ToList();
        if (items[0].IsHeaderTapped)
            return Color.Green;
        else
            return Color.Yellow;
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

C#

In ItemTapped Event, change the model property value for the respective group header and refresh the listview item by using Listview.RefreshListViewItem

private void ListView_ItemTapped(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e)
{
    var groupResult = e.ItemData as GroupResult;
    if (e.ItemType is ItemType.GroupHeader)
    {
        foreach (var item in groupResult.Items)
        {
            if (!(item as Contacts).IsHeaderTapped)
                (item as Contacts).IsHeaderTapped = true;
            else
                (item as Contacts).IsHeaderTapped = false;
        }
        listView.RefreshListViewItem(-1, -1, true);
    }
}

XAML

Bind the BackgroundColor property with GroupHeaderConverter in GroupHeaderTemplate.

<syncfusion:SfListView.GroupHeaderTemplate>
    <DataTemplate >
        <Grid x:Name="headergrid" BackgroundColor="{Binding .,
            Converter={StaticResource GroupHeaderConverter}}" >
            <Label x:Name="label" Text="{Binding Key}"  />
        </Grid>
    </DataTemplate>
</syncfusion:SfListView.GroupHeaderTemplate>

Output

GroupHeaderColorOnTap

group-header-color-on-tap-listview-xamarin's People

Contributors

jayaleshwari avatar sarubala20 avatar vinothkumar-ganesan avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.