selectionchanged event not triggering

as you can see i have taken a SfChipGroup to display the color palette on the screen  
But I won't be able to get the selected color value on this event SfChipGroup_SelectionChanged
Please help!

Code  - Color.xaml

<buttons:SfChipGroup x:Name="TextColor" Type="Action" Margin="18,0,18,0" SelectionIndicatorColor="#9900CC" SelectionChanged="SfChipGroup_SelectionChanged" >
                                    <buttons:SfChipGroup.Items>
                                        <buttons:SfChip  BackgroundColor="#EB5757" HeightRequest="50" WidthRequest="50"/>
                                        <buttons:SfChip BackgroundColor="#F2994A" HeightRequest="50" WidthRequest="50"/>
                                        <buttons:SfChip BackgroundColor="#F2C94C" HeightRequest="50" WidthRequest="50"/>
                                        <buttons:SfChip BackgroundColor="#219653" HeightRequest="50" WidthRequest="50"/>
                                        <buttons:SfChip BackgroundColor="#2F80ED" HeightRequest="50" WidthRequest="50"/>
                                        <buttons:SfChip BackgroundColor="#9B51E0" HeightRequest="50" WidthRequest="50"/>
                                        <buttons:SfChip BackgroundColor="#333333" HeightRequest="50" WidthRequest="50"/>
                                        <buttons:SfChip BackgroundColor="#FFFFFF" HeightRequest="50" WidthRequest="50"/>
                                    </buttons:SfChipGroup.Items>
                                </buttons:SfChipGroup>



Code  - Color.xaml.cs

 private void SfChipGroup_SelectionChanged(object sender, Syncfusion.Buttons.XForms.SfChip.SelectionChangedEventArgs e)
        {
            //To get the recently selected and unselected chip 
            var selectedIndex = e.AddedItem;
        }

1 Reply 1 reply marked as answer

HM Hemalatha Marikumar Syncfusion Team August 5, 2020 04:55 PM UTC

Hi Shraddha, 
 
Greetings from Syncfusion.  
 
We would like to let you know that SelectionChanged event invoked only for ChipGroup types Choice and Filter. Action type is only for invoking the Command action while tapping the Chip items. But your requirement has been achieved with the help of Command property in ChipGroup. While tapping chip, it executed Command and itself has argument as selected chip.  
 
By getting that Background color, we can obtain that color value of tapped chips as per in below code snippet 
 
Here we have bound the color of tapped chip to BoxView. 
 
<ContentPage.BindingContext> 
        <local:ViewModel/> 
    </ContentPage.BindingContext> 
     
    <ContentPage.Content> 
        <StackLayout> 
        <buttons:SfChipGroup x:Name="TextColor" Type="Action" Command="{Binding ChipCommand}" Margin="18,0,18,0" SelectionIndicatorColor="#9900CC"  > 
                <buttons:SfChipGroup.Items> 
                    <buttons:SfChip  BackgroundColor="#EB5757" HeightRequest="50" WidthRequest="50"/> 
                    <buttons:SfChip BackgroundColor="#F2994A" HeightRequest="50" WidthRequest="50"/> 
                    <buttons:SfChip BackgroundColor="#F2C94C" HeightRequest="50" WidthRequest="50"/> 
                    <buttons:SfChip BackgroundColor="#219653" HeightRequest="50" WidthRequest="50"/> 
                    <buttons:SfChip BackgroundColor="#2F80ED" HeightRequest="50" WidthRequest="50"/> 
                    <buttons:SfChip BackgroundColor="#9B51E0" HeightRequest="50" WidthRequest="50"/> 
                    <buttons:SfChip BackgroundColor="#333333" HeightRequest="50" WidthRequest="50"/> 
                    <buttons:SfChip BackgroundColor="#FFFFFF" HeightRequest="50" WidthRequest="50"/> 
                </buttons:SfChipGroup.Items> 
            </buttons:SfChipGroup> 
            <BoxView Margin="0,30,0,0" Color="{Binding SelectedColor}" HeightRequest="40" WidthRequest="40" HorizontalOptions="Center" VerticalOptions="Center"/> 
        </StackLayout> 
    </ContentPage.Content> 
 
public class ViewModel :INotifyPropertyChanged 
    { 
 
        private Color selectedColor; 
 
        public event PropertyChangedEventHandler PropertyChanged; 
 
        public Color SelectedColor 
        { 
            get { return selectedColor; } 
            set 
            { 
                selectedColor = value; 
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SelectedColor")); 
            } 
        } 
 
        public Command ChipCommand { get; set; } 
 
        public ViewModel() 
        { 
            ChipCommand = new Command<object>(ChipCommandEx); 
 
        } 
 
        private void ChipCommandEx(object obj) 
        { 
            SelectedColor = (obj as SfChip).BackgroundColor; 
        } 
    } 
 
Output be like 
 



Sample Link: 
 
 
Please check and let us know your comments.  
 
Regards,
Hemalatha M. 


Marked as answer
Loader.
Up arrow icon