How do I get a Visual (e.g. a UserControl) to be ready for copying by a RenderTargetBitmap?

73 views Asked by At

The question has now been answered in a comment.

Original question:

The following is not enough:

this.Background = Brushes.Yellow;
RenderTargetBitmap bmp = new RenderTargetBitmap(...);
Measure(...);
Arrange(...);
bmp.Render(this);

If the color was different before this code being executed, the color is still the old color instead of changing to yellow.

So what step am I missing?

(It does work if I add an await Task.Delay(100); before rendering it, but seems to be an ugly workaround.)

1

There are 1 answers

0
ispiro On BEST ANSWER

[posting a temporary answer until the commenter posts their own.]

The problem was solved in a comment - adding UpdateLayout before rendering the Visual to the bitmap was enough.