How can we set border and background color in the WPF grid control ,
i am creating rows and column dynamically and adding then to grid,
can we set color and border from the code behind?
How can we set border and background color in the WPF grid control ,
Share
The
Backgroundcolor can just be set for the entireGridby using theBackgroundproperty:Or if you want it set for individual cells, you need to add an element to the cell that has its
Backgroundproperty set.As for Borders, a
Gridonly contains theShowGridLinesproperty, which can be used to show thin dotted lines that cannot be styled.Per MSDN:
So in order to add borders to your Grid, you have to add
Borderelements or controls that contain aBorderto the Grid cells, and style those elements.But there is an alternative. This blog post outlines how you can extend the Grid class to create a custom Grid that has properties for
Gridlines. I’ve used it successfully in the past when I wanted to render grid lines, but didn’t want to fill every cell with an object.