8

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-Window). Now I have detected that this can be very slow on older PC's which is a problem.

As a solution I thought about generating a graphic showing the UserControl and show this while resizing/dragging the Control, to prevent WPF from recalculating all Elements permanently. The only problem is that I have no idea how to generate this image.

Is there perhaps something like a function which does this in .Net? Or how could I do this on my own?

James Webster
  • 4,046
  • 29
  • 41
Tokk
  • 4,499
  • 2
  • 31
  • 47
  • This question/answer helped me as well: http://stackoverflow.com/questions/2557183/drawing-a-wpf-usercontrol-with-databinding-to-an-image – Aaron Hoffman Aug 26 '12 at 21:04

2 Answers2

8

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)

Community
  • 1
  • 1
Scott
  • 533
  • 1
  • 3
  • 10
0

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.

James Webster
  • 4,046
  • 29
  • 41
  • Hmmh, I looked at FixedDocument but according to Microsoft it provides readonly access for the user. I would need write, too. – Tokk Mar 23 '11 at 10:56
  • I really think you need to consider Windows Forms instead for your application if it needs to run on older hardware. Alternatively, you can simplify your UI, or maybe do some profiling to see where the hotspots in the front-end are. – James Webster Mar 23 '11 at 11:01
  • Well, that is not an option ;-) – Tokk Mar 23 '11 at 11:40