Articles in this section
Category / Section

How to display each chip in different colors in the Xamarin.Forms ChipGroup?

1 min read

You can display each chip in different colors by using the ItemTemplate support of SfChipGroup and the BackgroundColor property of SfChip.

The following code sample explains how to display each chip in different colors of the ChipGroup.

XAML:

<syncfusion:SfChipGroup ItemsSource="{Binding Employees}" ChipBackgroundColor="Transparent"
    SelectedChipBackgroundColor="Transparent" Type="Filter" >
 
    <syncfusion:SfChipGroup.ItemTemplate>
        <DataTemplate>
            <StackLayout>
                <syncfusion:SfChip Text="{Binding Name}" BackgroundColor="{Binding ChipColor}"/>
            </StackLayout>
        </DataTemplate>
    </syncfusion:SfChipGroup.ItemTemplate>
 
    <syncfusion:SfChipGroup.ChipLayout>
        <FlexLayout HorizontalOptions="Start" 
    VerticalOptions="Center" 
    Direction="Row" 
    Wrap="Wrap"
    JustifyContent="Start"
    AlignContent="Start" 
    AlignItems="Start"/>
    </syncfusion:SfChipGroup.ChipLayout>
 
</syncfusion:SfChipGroup>

C#:

public class ViewModel : INotifyPropertyChanged
{
    private ObservableCollection<Model> employees;
    public ObservableCollection<Model> Employees
    {
        get { return employees; }
        set
        {
            employees = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Employees"));
        }
    }
 
    public ViewModel()
    {
        Employees = new ObservableCollection<Model>()
        {
            new Model() { Name = "John", ChipColor = Color.DarkCyan },
            new Model() { Name = "James", ChipColor = Color.Black },
            new Model() { Name = "Linda", ChipColor = Color.DarkBlue },
            new Model() { Name = "Mark", ChipColor = Color.DeepPink }
        };
    }
}

Output:

SfChip with different colors

See Also:

 

Customize the appearance of Xamarin SfChip

 

How to change the chips type in Xamarin SfChip

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied