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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Dynamic Row background colour based on property from viewmodel

Thread ID:





126244 Oct 4,2016 01:12 AM UTC Dec 8,2017 03:41 AM UTC UWP 3
Tags: SfDataGrid
Asked On October 4, 2016 01:12 AM UTC


I'm trying to set my Row background colour dynamically using my viewmodel. As the viewmodel value changes I want the background colour to automatically change. For example if my model has a bool property called IsActive, I want to create a binding where true would result in purple while false would result in white. Any advice?

Sowndaiyan Paulpandi [Syncfusion]
Replied On October 4, 2016 12:34 PM UTC

Hi Arvin,

Thanks for contacting Syncfusion Support

In the SfDataGrid, it is possible to change the Row style at run time. You can change the Row style while changing the cell data by using  the SfDataGrid.CurrentCellEndEdit event along with the RowStyleSelector. We have prepared a sample as per your requirement and you can download the sample from the below location,

Sample : http://www.syncfusion.com/downloads/support/forum/126244/ze/UWP-330020962 

Please refer the below UG link to know more about RowStyleSelector

UG : https://help.syncfusion.com/wpf/sfdatagrid/conditional-styling#styling-rows-using-styleselector

Peter Verbo
Replied On December 6, 2017 08:48 PM UTC

I have little bit different approach with using SetterValueBindingHelper:


        <Style x:Key="rowStyle" TargetType="sfDataGrid:VirtualizingCellsControl">
            <Setter Property="utils:SetterValueBindingHelper.PropertyBinding">
                    <utils:SetterValueBindingHelper Property="Background" Binding="{Binding Converter={StaticResource DataGridCellBackgroundConverter}}"/>

    public class DataGridCellBackgroundConverter : IValueConverter
        public object Convert(object value, Type targetType, object parameter, string culture)
            if (value is Command)
                MyClass item = value as MyClass;
                return new SolidColorBrush(item.IsActive ? Colors.LightGreen : Colors.Gray);
            return new SolidColorBrush(Colors.White);
        public object ConvertBack(object value, Type targetType, object parameter, string culture)
            throw new NotImplementedException();

Gnanasownthari Thirugnanam [Syncfusion]
Replied On December 8, 2017 03:41 AM UTC

Hi Peter, 

Thank you for providing your suggested solution in Syncfusion forum. 

Please let us know if you need further assistance on this. 

Gnanasownthari T. 


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

or the page will be automatically redirected to 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