internal void ChangeFormat()
{
foreach (var cell in gridCells)
{
var i = r.Next(0, 10);
if (i < 2)
{
cell.Background = new SolidColorBrush(Colors.Yellow) { Opacity = 0.5 };
cell.Foreground = Brushes.Brown;
cell.FontWeight = FontWeights.UltraBold;
cell.BorderBrush = Brushes.Red;
cell.BorderThickness = new Thickness(2);
}
else if (i < 5)
{
cell.Background = new SolidColorBrush(Colors.Blue) { Opacity = 0.5 };
cell.Foreground = Brushes.White;
cell.FontWeight = FontWeights.SemiBold;
cell.BorderBrush = Brushes.AntiqueWhite;
cell.BorderThickness = new Thickness(1);
}
else if (i < 8)
{
cell.Background = new SolidColorBrush(Colors.White) { Opacity = 0.5 };
cell.Foreground = Brushes.Blue;
cell.FontWeight = FontWeights.Normal;
cell.BorderBrush = Brushes.Gray;
cell.BorderThickness = new Thickness(1);
}
else
{
cell.Background = new SolidColorBrush(Colors.Brown) { Opacity = 0.5 };
cell.Foreground = Brushes.Yellow;
cell.FontWeight = FontWeights.Normal;
cell.BorderBrush = Brushes.Black;
cell.BorderThickness = new Thickness(2);
}
}
} |
Query |
Response |
I just noticed that if I apply { Opacity = 0.5 } to the background color, then the color I set is different than what I want, is there a way to avoid this? |
There is no other way to avoid this behavior. Based on our control structure, the background color applied for the cell will be above the selection/hover color. Hence the only way to resolve this is to set opacity for the Background brush. |
Actuall behavior:
1. foreground set to blue
2. select that cell and select the some other cell
3. the first cell's foreground become black
What I want is it will still the same color even after selection. |
We have checked this. This will occur only using CustomerRowGenerator to change the foreground color of the cells. We suggest you to achieve your styling related requirement by including Style with terget type as GridCell as given in the following references.
UG references :
|