Reputation: 15057
I have a grid (table) like structure with rows and columns, and I am assigning the background color for every cell using the border
object.
How do I change the background color for every cell of the grid?
This is my approach:
Delete the border object and assign it a new one.
I have also tried to create a new Border
object, and add it. But it throws InvalidOperationException
stating "Element is already the child of another element".
How can I change the background color for a particular table row?
Upvotes: 0
Views: 206
Reputation: 4847
Now that I better understand your question...
The following code will give you the border in Row r
and Column c
.
var border = myGrid.Children.OfType<Border>().Where(x => Grid.GetRow(x) == r && Grid.GetColumn(x) == c).FirstOrDefault();
border.Background = [...];
Hope this helps.
Upvotes: 2