I’m new to WPF, and trying to add a 1 pixel border or space between elements in a UniformGrid. How can I do this? I tried adding a Margin to each child element, but that creates a two pixel border between cells in the middle. I could add a margin to top and left, but that would make the bottom and right cells have no outside margin.
I tried googling, probably not using the right terms.
You said you tried setting Margin to 1, which gives you a total of 2 pixels around each element.
So cut it in half; set your items’ margins to 0.5 instead. You’ll also want to add a Margin of 0.5 to the UniformGrid itself, so everything ends up lining up on pixel boundaries.
(The leftmost column of items will have the UniformGrid’s 0.5-pixel left margin, plus the item’s 0.5-pixel margin, for a total of 1 pixel. Then between that first column and the next column, you’ll have the first column’s 0.5-pixel right margin, plus the next column’s 0.5-pixel left margin, so once again you’ve got 1 pixel total between columns. It works out nicely.)