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

Change the Background of a row dynamically

Thread ID:

Created:

Updated:

Platform:

Replies:

149375 Nov 23,2019 07:09 PM UTC Nov 28,2019 05:48 AM UTC WPF 4
loading
Tags: SfDataGrid
Helmut Wahrmann
Asked On November 23, 2019 07:09 PM UTC

Hi,

i am using the conditional styling approach using your samples at: https://help.syncfusion.com/wpf/datagrid/conditional-styling#row-style
My Converter is called and i am setting rows.

The content of the row is bound to a collection in my ViewModel and when i change some value, the row color should be checked.
However the color converter is only called, when the grid is initally displayed.
The grid in my MVVM view seems not to recognize, that the bound column has been changed and the converter is not called.

Note: that i see the changed values in the grid appear. so the binding is ok.

Any ideas?

thanks,

Helmut

Helmut Wahrmann
Replied On November 24, 2019 09:17 AM UTC

Ok, i found it using the hint in your KB article: https://www.syncfusion.com/kb/6658/how-to-change-row-background-based-on-record

I set the Path and now it works:

    <Style TargetType="syncfusion:VirtualizingCellsControl" x:Key="changedRowStyle">
      <Setter Property="Background" Value="{Binding Path=Changed,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource changedRowStyleSelector}}"/>
    </Style>

Only drawback now is that i need to have a second ColorConverter, since i am using also an alternate roswstyle and the colorconverter is bound to rowstyle, which is only called for odd rows.

Mohanram Anbukkarasu [Syncfusion]
Replied On November 25, 2019 12:16 PM UTC

Hi Helmut,   
  
Thanks for contacting Syncfusion support.    
  
The converter bound to the RowStyle will be called only for the odd rows as you specified when alternative row style is applied. You need to create another converter and bind it to the AlternativeRowStyle as specified in the below code example.   
  
Code example:    
  
XAML:    
  
<Window.Resources>   
    <local:CustomRowStyleConverter x:Key="CustomRowStyleConverter" />   
    <local:AlternativeRowStyleConverter x:Key="AlternativeRowStyleConverter" />   
    <Style x:Key="rowStyle" TargetType="Syncfusion:VirtualizingCellsControl">   
        <Setter Property="Background" Value="{Binding Converter={StaticResource CustomRowStyleConverter}, UpdateSourceTrigger=PropertyChanged}" />   
    </Style>   
    <Style x:Key="alternativeRowStyle" TargetType="Syncfusion:VirtualizingCellsControl">   
        <Setter Property="Background" Value="{Binding Converter={StaticResource AlternativeRowStyleConverter},UpdateSourceTrigger=PropertyChanged}"/>   
    </Style>   
</Window.Resources>   
   
<Syncfusion:SfDataGrid x:Name="datagrid"   
                       AllowEditing="True"   
                       ItemsSource="{Binding ItemsCollection}"   
                       RowStyle="{StaticResource rowStyle}"   
                       AlternatingRowStyle="{StaticResource alternativeRowStyle}" />   
  
  
CS:    
  
public class CustomRowStyleConverter : IValueConverter   
{   
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)   
    {   
        if (value == null)   
            return DependencyProperty.UnsetValue;   
   
        if ((value as BusinessObjects).IsChecked)   
            return new SolidColorBrush(Colors.Green) { Opacity = 0.7 };   
        return new SolidColorBrush(Colors.AliceBlue);   
    }   
   
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo cultur   
    {   
        throw new NotImplementedException();   
    }   
}   
   
public class AlternativeRowStyleConverter : IValueConverter   
{   
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)   
    {   
        if (value == null)   
            return DependencyProperty.UnsetValue;   
   
        if ((value as BusinessObjects).IsChecked)   
            return new SolidColorBrush(Colors.Green) { Opacity = 0.7 };   
        return new SolidColorBrush(Colors.Beige);   
    }   
   
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo cultur   
    {   
        throw new NotImplementedException();   
    }   
}   
  
  
  
Please let us know if you require further other assistance from us.    
  
Regards,   
Mohanram A  


Helmut Wahrmann
Replied On November 27, 2019 08:13 PM UTC

That's exactly what i did.
Thanks for the confirmation

Farjana Parveen Ayubb [Syncfusion]
Replied On November 28, 2019 05:48 AM UTC

Hi Helmut, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Farjana Parveen A 


CONFIRMATION

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