Create WPF element offscreen and render to bitmap

前端 未结 1 1741
梦毁少年i
梦毁少年i 2020-12-05 18:28

I can\'t understand why this doesn\'t work, or what I need to get it to work.

To repro, create a simple WPF application and replace the main window\'s constructor th

相关标签:
1条回答
  • 2020-12-05 19:02

    Because elements don't have a desired size until you measure them. You were telling the Grid to size itself with an available space of 0x0. Change your code to:

    grid.Measure(new Size(grid.Width, grid.Height));
    grid.Arrange(new Rect(new Size(grid.Width, grid.Height)));
    

    (The call to UpdateLayout is unneeded.)

    0 讨论(0)
提交回复
热议问题