Drawing a WPF UserControl with DataBinding to an Image

前端 未结 3 2123
礼貌的吻别
礼貌的吻别 2020-12-09 00:58

So I\'m trying to use a WPF User Control to generate a ton of images from a dataset where each item in the dataset would produce an image...

I\'m hoping I can set it

3条回答
  •  感动是毒
    2020-12-09 01:13

    Well, one of your problems is that you need to call Measure and Arrange on your UserControl before trying to render. Put this before creating the RenderTargetBitmap object:

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

    That will at least get your UserControl to start rendering.

    The second problem is the data binding. I haven't been able to crack that one; there may be something extra you need to do to get the bindings to evaluate. However, you can work around it: If you set the TextBlock contents directly rather than through data binding, it does work.

提交回复
热议问题