I have a radgrid set up that displays two columns which are NOT auto generated. Using some of your other examples, I have found a way to color an entire row if the value of the text in a particular column is set to a certain status, using a custom converter class.
I am at a loss however as to how to apply this only to a single column or the cells in that column. In other words how do I change the background color for cells in a single column rather than the entire row or every cell for that matter? This seems like it should be relatively simple, but I have not come across any supporting documentation with a straightforward example.
Here is the XAML I have currently for the grid that sets the entire row color:
My grid.resources definition where I reference my custom class:
XAML For the RadGrid Itself:
Custom Color Converter Class:
Again this works well for coloring the entire row, but I require only the cells in a single column to change color.
Any guidance would be appreciated.
Thank you in advance.
I am at a loss however as to how to apply this only to a single column or the cells in that column. In other words how do I change the background color for cells in a single column rather than the entire row or every cell for that matter? This seems like it should be relatively simple, but I have not come across any supporting documentation with a straightforward example.
Here is the XAML I have currently for the grid that sets the entire row color:
My grid.resources definition where I reference my custom class:
<
Grid.Resources
>
<
local:StatusColorConverter
x:Key
=
"ColorConverter"
></
local:StatusColorConverter
>
</
Grid.Resources
>
XAML For the RadGrid Itself:
<
telerik:RadGridView
Name
=
"radGrid1"
HorizontalAlignment
=
"Stretch"
VerticalAlignment
=
"Stretch"
ShowGroupPanel
=
"False"
Margin
=
"5,10,0,100"
DataLoaded
=
"radGrid1_DataLoaded"
SelectionChanged
=
"radGrid1_SelectionChanged"
AutoGenerateColumns
=
"False"
IsFilteringAllowed
=
"False"
ItemsSource
=
"{Binding}"
EnableColumnVirtualization
=
"False"
CanUserResizeColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Name"
DataMemberBinding
=
"{Binding SerialNumber}"
IsReadOnly
=
"True"
UniqueName
=
"Name"
ShowFilterButton
=
"False"
AllowDrop
=
"False"
FooterTextAlignment
=
"Left"
Width
=
"Auto"
/>
<
telerik:GridViewDataColumn
Header
=
"Status"
DataMemberBinding
=
"{Binding StatusDescription}"
IsReadOnly
=
"True"
UniqueName
=
"Status"
ShowFilterButton
=
"False"
Width
=
"Auto"
/>
</
telerik:RadGridView.Columns
>
<
telerik:RadGridView.RowStyle
>
<
Style
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"Background"
Value
=
"{Binding Status,Converter={StaticResource ColorConverter}}"
></
Setter
>
</
Style
>
</
telerik:RadGridView.RowStyle
>
</
telerik:RadGridView
>
Custom Color Converter Class:
public class StatusColorConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Status status = (Status)value;
SolidColorBrush color = null;
switch (status)
{
case Status.Status_A:
case Status.Status_B:
color = new SolidColorBrush(Colors.Red);
break;
case Status.Status_C:
color = new SolidColorBrush(Colors.Green);
break;
default:
// No color by default.
color = new SolidColorBrush();
break;
}
return color;
}
Again this works well for coloring the entire row, but I require only the cells in a single column to change color.
Any guidance would be appreciated.
Thank you in advance.