How to display chip in different colors in Xamarin.Forms ChipGroup?
You can display each chip in different colors by using the ItemTemplate support of Xamarin.Forms ChipGroup 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:
See Also:
Customize the appearance of Xamarin SfChip
How to change the chips type in Xamarin SfChip
Conclusion
I hope you enjoyed learning about how to display chip in different colors in Xamarin.Forms ChipGroup.
You can refer to our Xamarin.Forms ChipGroup feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!