Sorry if you think this question was already answered, I did look everywhere trying to find out how come when I do this, it is not displaying anything. This is all my code:<
A WPF UIElement has to be laid out before being visible. It has to get at least one Measure
and Arrange
call, where it gets an available Size and a final arrange Rect (usually from its parent Panel). When rendering a newly created element into a RenderTargetBitmap, you would call these methods manually, with appropriate values for the Size and Rect:
...
hexagon.Measure(new Size(200, 200)); // adjust this to your needs
hexagon.Arrange(new Rect(0, 0, 200, 200)); // adjust this to your needs
var bmp = new RenderTargetBitmap(200, 200, 96, 96, PixelFormats.Default);
bmp.Render(hexagon);