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

Customize the background color in SfComboBox

Thread ID:





145713 Jul 4,2019 10:41 PM UTC Jul 8,2019 01:43 PM UTC Xamarin.Forms 5
Tags: SfComboBox
Julio Cézar
Asked On July 4, 2019 10:41 PM UTC

I use Xamarin.Forms with the SfComboBox component.
I need to customize the background of each combobox item based on a value in my class.

The datasource of the combobox is prrenched with a List <Product>.

The Product class is composed by: int idproduct, string dsproduct, int amount.

I need to change the background color of each item based on the amount field, for example: if amount <= 0 the background should be red, if amount > 0 the background should be blue.

Does anyone have an example of how to do this?
Can you help?

Muneesh Kumar G [Syncfusion]
Replied On July 5, 2019 07:19 AM UTC

Hi Julio, 
Greetings from Syncfusion.  
We have analyzed your requirement and you can achieve this by using DataTemplateSelector support, it has been implemented in our latest Beta version.  
We have prepared a sample for the same. Please have the sample from the below link, 
Code Snippet: 

            <DataTemplate x:Key="default">
            <DataTemplate x:Key="specific">
        <Label Text="High performance Mobiles" FontSize="Medium" FontAttributes="Bold"/>
        <Label Text="Choose a Device to place order" FontAttributes="None" FontSize="Micro"/>
            <combobox:SfComboBox DataSource="{Binding Data}" x:Name="comboBox" DisplayMemberPath="dsproduct">
                        DefaultTemplate="{StaticResource default}" 
                        SpecificDataTemplate="{StaticResource specific}"/>
 protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
            var message = item as Product;
            return message.amount <= 0 ? DefaultTemplate : SpecificDataTemplate;
Screenshot :  
Please check with the sample and let us know if you have any concern. 
Muneesh Kumar G.  

Julio Cézar
Replied On July 8, 2019 12:32 PM UTC

Thank you

Muneesh Kumar G [Syncfusion]
Replied On July 8, 2019 01:30 PM UTC

Hi Julio,  
Please let us know if you have any other queries.  
Muneesh Kumar G. 

Julio Cézar
Replied On July 8, 2019 01:34 PM UTC

At the moment, none.
Everything working perfectly.
Thank you.

Muneesh Kumar G [Syncfusion]
Replied On July 8, 2019 01:43 PM UTC

Hi Julio,   
Thank you.  
Muneesh Kumar G.  


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

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

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
Live Chat Icon