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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to restrict chip selection in Xamarin

Platform: Xamarin.Forms |
Control: SfChipGroup |
Published Date: March 13, 2020 |
Last Revised Date: March 13, 2020

 

This article explains how to restrict the chip selection in Xamarin ChipGroup.

 

Consider if your requirement is to restrict a specific chip from the selection process, it can be achieved by controlling the selection functionality using the SelectionChanging event Cancel argument.

 

Note:

It restricts the chip selection when you set Cancel value to true.

 

Here, users are allowed to select all languages except Java. 

 

XAML

 

<buttons:SfChipGroup 
    Type="Filter" 
    ItemsSource="{Binding Languages}"
    SelectedChipBackgroundColor="Red"
    ChipPadding="8,8,0,0"
    SelectionIndicatorColor="White"
    SelectionChanging="SfChipGroup_SelectionChanging"
    DisplayMemberPath="Name">
</buttons:SfChipGroup>

 

C#

 

        private void SfChipGroup_SelectionChanging(object sender, Syncfusion.Buttons.XForms.SfChip.SelectionChangingEventArgs e)
        {
          if(e.AddedItem != null && (e.AddedItem as Language).Name.Equals("Java"))
            {
                e.Cancel = true;
            }
        }

 

public class ViewModel : INotifyPropertyChanged
    {
        private ObservableCollection<Language> languages;
        public ObservableCollection<Language> Languages
        {
            get
            {
                return languages;
            }
 
            set
            {
                languages = value;
                OnPropertyChanged("Languages");
            }
        }
 
        public ViewModel()
        {
            Languages = new ObservableCollection<Language>();
            Languages.Add(new Language () { Name = "C#" });
            Languages.Add(new Language () { Name = "HTML" });
            Languages.Add(new Language () { Name = "Java" });
            Languages.Add(new Language () { Name = "JS" });
        }
 
       ..
 
    }

 

Output

Restrict chip selection in Xamarin.Forms SfChipGroup.

 

See Also:

 

What are the types available in ChipGroup?

 

What are the customizations available in ChipGroup?

How to notify selection changes in ChipGroup?

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile