Dynamic Row background colour based on property from viewmodel
Hi,
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?
SIGN IN To post a reply.
3 Replies
SP
Sowndaiyan Paulpandi
Syncfusion Team
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
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
Regards,
Sowndaiyan
Sowndaiyan
PV
Peter Verbo
December 6, 2017 08:48 PM UTC
I have little bit different approach with using SetterValueBindingHelper:
xmlns:utils="using:Syncfusion.UI.Xaml.Utils"
<Style x:Key="rowStyle" TargetType="sfDataGrid:VirtualizingCellsControl">
<Setter Property="utils:SetterValueBindingHelper.PropertyBinding">
<Setter.Value>
<utils:SetterValueBindingHelper Property="Background" Binding="{Binding Converter={StaticResource DataGridCellBackgroundConverter}}"/>
</Setter.Value>
</Setter>
<Setter Property="utils:SetterValueBindingHelper.PropertyBinding">
<Setter.Value>
<utils:SetterValueBindingHelper Property="Background" Binding="{Binding Converter={StaticResource DataGridCellBackgroundConverter}}"/>
</Setter.Value>
</Setter>
...
</Style>
Converter:
public class DataGridCellBackgroundConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string culture)
{
if (value is Command)
{
MyClass item = value as MyClass;
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();
}
}
{
throw new NotImplementedException();
}
}
GT
Gnanasownthari Thirugnanam
Syncfusion Team
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.
Regards,
Gnanasownthari T.
SIGN IN To post a reply.
- 3 Replies
- 4 Participants
-
AR Arvin
- Oct 4, 2016 01:12 AM UTC
- Dec 8, 2017 03:41 AM UTC