How to create an image of a WPF UserControl at runtime

前端 未结 2 1185
死守一世寂寞
死守一世寂寞 2020-12-01 22:15

I\'ve created a WPF application which has a Canvas on which I place UserControls which are moveable and resizeable by the user (just like a Windows

相关标签:
2条回答
  • 2020-12-01 22:48

    WPF applications really do require some fairly serious grunt; particularly in the graphics department and benefit greatly from having a decent video card present in the system. Even then the performance of WPF apps (if not carefully constructed) can leave much to be desired...

    That said, you could feasibly use FixedDocument to rasterise a UserControl, and then convert this into a GIF/JPG/PNG and put this in place of the control being resized... however I would expect that process itself to be as slow or slower than your current observed performance issues.

    0 讨论(0)
  • 2020-12-01 23:02

    You can render a WPF control to a bitmap using RenderTargetBitmap, then this image can be copied to the clipboard, saved to a file, or used as part of your GUI

    Check out Get a bitmap image from a Control view

    Beware with this that you can hit problems when parts of the control you are trying to render are not visible (within a scroll viewer perhaps)

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