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

sfDataGrid RowStyling from MultiConverter

Thread ID:

Created:

Updated:

Platform:

Replies:

141118 Nov 25,2018 12:44 PM UTC Dec 3,2018 03:18 PM UTC WPF 7
loading
Tags: SfDataGrid
Vasudeva Naik
Asked On November 25, 2018 12:44 PM UTC

Hi ,
I have several properties of a row item depending on which, I need to pick up a row style.
Style selector isn't something I can use as the styles should be updated on property change of each of these depending property. I am trying to set up the row style of the grid like this:

 <controls:sfDataGrid.RowStyle>
                <MultiBinding Converter="{StaticResource RowBackgroundConverter}">
                    <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}"/>
                    <Binding Path="Property1" UpdateSourceTrigger="PropertyChanged"/>
                    <Binding Path="Property2" UpdateSourceTrigger="PropertyChanged"/>
                </MultiBinding>
            </controls:sfDataGrid.RowStyle>

However, this isn't working as it is trying to search the Property1 and Property2 in the datacontext of the grid (it should search in row item).
Do we something like:
  <Binding Path="Data.Property1" UpdateSourceTrigger="PropertyChanged"/>
  <Binding Path="Data.Property2" UpdateSourceTrigger="PropertyChanged"/>
?
If not, how do I hook up the correct data context.

regards,
Sid


Deivaselvan Y [Syncfusion]
Replied On November 28, 2018 05:07 AM UTC

Hi Vasudeva,

You can achieve your requirement to change the row background based on multiple value changes at runtime using MultiBindingConverter. Please refer the below sample to demonstrate it and let us know if this helps you.

http://www.syncfusion.com/downloads/support/directtrac/221368/ze/AutoRefresh_MultiBinding1516573648.zip

You can also refer the below article for the same.
https://www.syncfusion.com/kb/6646/how-to-change-the-row-background-based-on-property-in-record

Regards,
Deivaselvan  


Vasudeva Naik
Replied On November 28, 2018 06:22 AM UTC

Hi Deivaselvan   

Thanks for response.  I couldn't build the project. I've attached screenshot of reference issue. I managed to add other references except "Synchfusion.SampleLayout"


Thanks 


Attachment: AutoRefresh_MultiBinding_build_Issue_83398d41.zip

Deivaselvan Y [Syncfusion]
Replied On November 28, 2018 07:11 AM UTC

Hi Vasudeva,

“Syncfusion.SampleLayout.dll” was not required to run the given application. We have modified the sample with the required assembly references and you can find the modified sample from the below link.

http://www.syncfusion.com/downloads/support/forum/141118/ze/AutoRefresh_MultiBinding-282475302.zip

Please let us know if this helps you.

Regards,
Deivaselvan 


Vasudeva Naik
Replied On November 28, 2018 07:27 AM UTC

Hi,
Thank you for the response!
This is not exactly what I am trying to achieve. Its just a part of it.
If you see the code I have pasted: the attempt is not just to set the "Background color" but the entire row style.

Can you provide a sample for setting the entire row style rather than just the background?

regards,
Sid

Jayabharathi J [Syncfusion]
Replied On November 29, 2018 03:52 PM UTC

Hello team, any updates on this? This is urgent. Thanks 


Deivaselvan Y [Syncfusion]
Replied On November 29, 2018 04:04 PM UTC

Hi Vasudeva,

As of now, this is not feasible to get the underlying data value of the row by setting binding to the RowStyle property of SfDataGrid. Our previous solution is the possible way to change row property values based on underlying data value change at runtime. However, currently we are analyzing the feasibility by doing any customization in SfDataGrid to achieve your requirement to change the row style at runtime. We will update you with more details on November 30, 2018.

Regards,
Deivaselvan 


Deivaselvan Y [Syncfusion]
Replied On December 3, 2018 03:18 PM UTC

Hi Vasudeva, 

Thanks for your patience.

 
We have analyzed the feasibility to change the rowstyle at runtime and you can achieve this requirement by writing CustomVirtualizingCellsControl as like below code snippet. 

public class CustomVirtualizingCellsControl : VirtualizingCellsControl 
    { 
        void OnDataPropertyChanged(object sender, PropertyChangedEventArgs e) 
        { 
            var dataContext = this.DataContext as StockData; 
            if (dataContext != null) 
            { 
                if (dataContext.Change > 0 && dataContext.LastTrade >= 25) 
                    this.Style = App.Current.Resources["rowStyle1"] as Style; 
                else 
                    this.Style = App.Current.Resources["rowStyle2"] as Style; 
            } 
        } 
        } 

public class CustomRowGenerator : RowGenerator 
    { 
        public CustomRowGenerator(SfDataGrid dataGrid) 
            : base(dataGrid) 
        { 
        } 
 
        protected override VirtualizingCellsControl GetVirtualizingCellsControl<T>() 
        { 
            if (typeof(T) == typeof(VirtualizingCellsControl)) 
                return new CustomVirtualizingCellsControl(); 
            return base.GetVirtualizingCellsControl<VirtualizingCellsControl>(); 
        } 
    } 

We have prepared a demo sample to achieve your requirement and please find it from below link. Try running this sample and let us know if this helps you. 
 
Regards, 
Deivaselvan 


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

;