My scenario is fairly simple: I have a grid bound to a VirtualQueryableCollectionView that is loaded with DataRows. Each DataRow has a column containing an integer value for a color that I need to convert to a SolidColorBrush. I'm specifying the RadGridView.RowStyle and an IValueConverter to achieve the setting of the row background. The problem I'm seeing is that my converter is only called one time with a row that actually contains a DataRow for it's 'Item' property. That single call is for the row just out of view in the grid. None of the visible rows before it contain a DataRow as their GridViewRow.Item.
Here is my style attached to the grid:
<telerik:RadGridView.RowStyle>
<Style TargetType="telerik:GridViewRow">
<Setter Property="Background">
<Setter.Value>
<Binding RelativeSource="{RelativeSource Self}" Converter="{StaticResource DataGridRowBackgroundConverter}" ></Binding>
</Setter.Value>
</Setter>
</Style>
</telerik:RadGridView.RowStyle>
And here is the converter code. Note the comment on line 4:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var gridViewRow = (GridViewRow)value;
var dataRow = gridViewRow.Item as DataRow; // This is only true for a single row in the grid!
if (dataRow == null) return new SolidColorBrush(Colors.Transparent);
var integerValue = dataRow.Field<int>(DataSourceConstants.ColorColumnName);
if (integerValue == 0)
{
return new SolidColorBrush(Colors.Transparent);
}
var bytes = BitConverter.GetBytes(integerValue);
var color = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);
return new SolidColorBrush(color);
}
What could I be doing wrong here?
Here is my style attached to the grid:
<telerik:RadGridView.RowStyle>
<Style TargetType="telerik:GridViewRow">
<Setter Property="Background">
<Setter.Value>
<Binding RelativeSource="{RelativeSource Self}" Converter="{StaticResource DataGridRowBackgroundConverter}" ></Binding>
</Setter.Value>
</Setter>
</Style>
</telerik:RadGridView.RowStyle>
And here is the converter code. Note the comment on line 4:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var gridViewRow = (GridViewRow)value;
var dataRow = gridViewRow.Item as DataRow; // This is only true for a single row in the grid!
if (dataRow == null) return new SolidColorBrush(Colors.Transparent);
var integerValue = dataRow.Field<int>(DataSourceConstants.ColorColumnName);
if (integerValue == 0)
{
return new SolidColorBrush(Colors.Transparent);
}
var bytes = BitConverter.GetBytes(integerValue);
var color = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);
return new SolidColorBrush(color);
}
What could I be doing wrong here?