Adding a Gradient background to an SfChipGroup Chip item

Hi,

Is it possible to apply a gradient to the background of a chip item in a SfChipGroup? I'm looking for something similar to the SfButton background feature.


Thanks,

Andrew


5 Replies

AE Andrew Elliott August 9, 2022 09:21 AM UTC

Hi,

Is there any possibility that this feature will be added to an upcoming release or is there a workaround to add this functionality?


I noticed you had a sample screen shot in the template section that shows more or less the effect I am after, however I can't find the code for this particular screen in the template sample code?

 Chips.png


Thanks,

Andrew



VV Vijayakumar Viswanathan Syncfusion Team August 17, 2022 12:48 PM UTC

Hi Andrew,


Query 1: Is it possible to apply a gradient to the background of a chip item in a SfChipGroup?


In the SfChipGroup all the items are of the SfChip data type. The SfChip supports the background color gradient through the BackgroundGradient property. We can style the BackgroundGradient property of the SfChip item in the ResourceDictionary. We have prepared a sample for your reference, please get it from the attachment. Please let us know if you need any other details.


Thanks,

Vijayakumar V


Attachment: SfChipSample_2296d10e.zip


AE Andrew Elliott August 22, 2022 11:29 AM UTC

Hi  Vijayakumar,


Thank you very much for the provided sample. This does seem to allow me to set a gradient background however it is a little limited in that it doesn't allow the setting of different gradients based on the state of the chip. I have defined a variable list of items bound to a property in my View Model


View:

<chip:SfChipGroup Grid.Column="1" Grid.RowSpan="2"
      Style="{StaticResource chipYesNoItemStyle}" VerticalOptions="CenterAndExpand" Type="Choice" ChoiceMode="Single" WidthRequest="120" HorizontalOptions="CenterAndExpand" Margin="0,2,0,0" ItemsSource="{Binding ChipItems}" DisplayMemberPath="Name">

</chip:SfChipGroup>

Style:

            <Style x:Key="chipYesNoItemStyle" TargetType="Controls:CustomChipGroup">
                <Setter Property="SelectedChipBackgroundColor" Value="{StaticResource accentColour3}"/>
                <Setter Property="ChipBackgroundColor" Value="{StaticResource buttonBkgColour}"/>
                <Setter Property="ChipTextColor" Value="{StaticResource buttonFgColour}"/>
                <Setter Property="SelectedChipTextColor" Value="{StaticResource buttonFgColour}"/>
                <Setter Property="ChipImageWidth" Value="50"/>

                <Setter Property="Type" Value="Choice"/>
                <Setter Property="ChoiceMode" Value="Single"/>
                <Setter Property="HeightRequest" Value="40" />
            </Style>


ViewModel:

private ObservableCollection<ChipItem> _chipItems;
public ObservableCollection<ChipItem> ChipItems { get => _chipItems; set => this.RaiseAndSetIfChanged(ref _chipItems, value); }


public TestViewModel()
{
            ChipItems.Add(new ChipItem() { Name = "Yes", Id = 0 });
            ChipItems.Add(new ChipItem() { Name = "No", Id = 1 });
}


ChipItem:

    public class ChipItem

    {
        public int Id { get; set; }
        public string Name { get; set; }
    }


The problem is that there doesn't seem to be an easy way to specify different backgrounds for the selected and unselected state. All the items in the group have a "hard coded" background gradient. 


Thanks,

Andrew



VV Vijayakumar Viswanathan Syncfusion Team August 23, 2022 03:12 PM UTC

Hi Andrew,

 

Query 1: To specify different backgrounds for the selected and unselected state in SfChipGroup.

 

Currently, we are validating the reported issue and we will let you know the details on  August 26, 2022. We appreciate your patience until then.

 

Regards,

Vijayakumar V



VV Vijayakumar Viswanathan Syncfusion Team August 26, 2022 01:54 PM UTC

Hi Andrew,


Query: To specify different background gradients for the selected and unselected state in SfChipGroup.


In the SfChipGroup, we do not have direct support to change the background dynamically. We have prepared a workaround using the SfButton in the DataTemplate to display the items of the SfChipGroup. Using the SfButton Clicked event, we have changed the BackgroundGradient property for the selected and unselected Items of the SfChipGroup.


We have prepared a sample for your reference and please get it from the attachments. Please let us know if the problem was resolved on your side.


Regards,

Vijayakumar V


Attachment: SfChipSample_bfb42fef.zip

Loader.
Up arrow icon