This question is locked. New answers and comments are not allowed.
I have a requirement to allow users to color code rows in the grid. My first iteration is simply saving the hex value in the database and overriding the SelectStyle per one of your examples. I'm a little concerned about performance as our grids can be quite large. Is there a more efficient way?
public class MyStyleSelector : StyleSelector{ public override Style SelectStyle(object item, DependencyObject container) { var st = new Style(typeof(GridViewRow)); if (item is MyClass) { var myClass = item as MyClass; if (MyClass.RowColor != null) { st.Setters.Add(new Setter(GridViewRow.BackgroundProperty, GetColorFromHex(myClass.RowColor))); } } return st; } } private static SolidColorBrush GetColorFromHex(string myColor) { return new SolidColorBrush( Color.FromArgb( Convert.ToByte(myColor.Substring(1, 2), 16), Convert.ToByte(myColor.Substring(3, 2), 16), Convert.ToByte(myColor.Substring(5, 2), 16), Convert.ToByte(myColor.Substring(7, 2), 16) ) ); }}