Lets say we have a list of products and we need to mark higher prices (>15.00) with a red color. Something like :

We have to create a small IValueConverter. It will take care to convert the value of the price to the appropriate color:
public class PriceToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
SolidColorBrush brush = new SolidColorBrush();
decimal price = (decimal) value;
if (price > 15)
brush.Color = Colors.Red;
else
brush.Color = Colors.Green;
return brush;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
We use this converter to bind the Foreground property of the cell to the product’s Price :
<Grid>
<Grid.Resources>
<local:PriceToColorConverter x:Key="MyConverter" />
</Grid.Resources>
<telerik:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False" >
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding ProductName}" Header="Product" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Price}" Header="Price">
<telerik:GridViewDataColumn.CellStyle>
<Style TargetType="telerik:GridViewCell">
<Setter Property="Foreground" Value="{Binding Price, Converter={StaticResource MyConverter}}" />
</Style>
</telerik:GridViewDataColumn.CellStyle>
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</Grid>
aaeaabdc-e48f-4615-a8a3-1125c84b73f4|4|3.0
Categories:
Silverlight, Telerik
23. October 2011
Tags:
RadGridView, Silverlight, Telerik, Style, GridView