You do not want to go through the grid. Old-fashioned WinForms is thinking about this. Grids in WPF and Silverlight were redesigned with MVVM in mind; with separation of problems. Instead of manipulating the grid, you work directly with your objects tied to the grid. Thus, the grid just becomes a representation problem. His duty is to read objects and display information based on the data in these objects.
Instead, you should attach properties to the object you are attached to and have grid styles for color / font / etc. based on these parameters. To do this, you need to create an IValueConverter.
Here is an example of the converter that I have in WPF and Silverlight datagrid:
public class StateToBackgroundColorConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return Colors.White.ToString();
var state = (State) value;
return state.WebColor;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
In my XAML, I declare this as follows:
<UserControl.Resources>
<Converters:StateToBackgroundColorConverter x:Key="stateToBackgroundColorConverter"/>
</UserControl.Resources>
In a datagrid declaration in XAML, I indicate the use of a converter for a DataGridRow:
<toolkit:DataGrid.RowStyle>
<Style TargetType="{x:Type toolkit:DataGridRow}">
<Style.Setters>
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="{Binding AgentState.SubState, Converter={StaticResource subStateToColorConverter}}" />
<Setter Property="Background" Value="{Binding AgentState.State, Converter={StaticResource stateToBackgroundColorConverter}}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
</Style.Setters>
</Style>
</toolkit:DataGrid.RowStyle>
, . State ( AgentState, , AgentState). , .
, .