This question is locked. New answers and comments are not allowed.
Hi,
I have a custom column and I would like to set a background color. I know that I can use StyleSelector and it works fine but I want to close this logic in column definition. I was trying to set cell.Background in CreateCellElement method but with no effects:
So now I am doing this like this:
1. Why cell.Backround = ... doesn't work
2. Do you know other solution
I have a custom column and I would like to set a background color. I know that I can use StyleSelector and it works fine but I want to close this logic in column definition. I was trying to set cell.Background in CreateCellElement method but with no effects:
public class ColorColumn : GridViewDataColumn { public override FrameworkElement CreateCellElement( GridViewCell cell, object dataItem ) { cell.Background = CalculateCellColor( dataItem ); return new TextBlock { Text = CalculateCellValue( dataItem ) }; } }So now I am doing this like this:
public class ColorColumn : GridViewDataColumn { public ColorColumn() { this.CellStyleSelector = new ColorColumnStyleSelector(); } public override FrameworkElement CreateCellElement( GridViewCell cell, object dataItem ) { return new TextBlock { Text = CalculateCellValue( dataItem ) }; } private class ColorColumnStyleSelector : StyleSelector { ... } } 1. Why cell.Backround = ... doesn't work
2. Do you know other solution