Hi,
I am trying to apply functionality to dynamically change grid's row color.
Went through a number of examples, and… I can't get it to work.
Program runs into converter, returns a brush, but row's color remains unchanged. I use Office2010Silver theme.
Could you point what I made wrong?
Here is converter code:
C#class ItemTypeToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (targetType.Name != typeof(Brush).Name)
{
throw new InvalidOperationException("ItemTypeToColorConverter: TargetType must be a Brush.");
}
Brush b = Brushes.Blue;
if (((DataRowView)value)== null) return Brushes.White;
switch(((DataRowView)value).Row.Field<string>("rodzaj_poz"))
{
case "L":
b = Brushes.Red;
break;
case "D":
b = Brushes.RoyalBlue;
break;
default:
b = Brushes.White;
break;
}
return b;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
And XAML:
XAML<dxg:GridControl.View>
<dxg:TableView MultiSelectMode="Row" NavigationStyle="Row" ShowGroupPanel="True" >
<dxg:TableView.RowStyle>
<Style TargetType="{x:Type dxg:GridRowContent}" BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=RowStyle, ThemeName=Office2010Silver, IsThemeIndependent=True}}">
<Setter Property="Background" Value="{Binding Path=Row, Converter={StaticResource ResourceKey=ItemTypeToColor}}" /> </Style>
</dxg:TableView.RowStyle>
</dxg:TableView>
</dxg:GridControl.View>
I would appreciate any hint.
Best regards,
Radek
XAML