views:

311

answers:

2

Hi all,

I am working on an application that uses several large canvas controls (several thousand pixels across), layered on top of each other. The canvas controls themselves are completely invisible, but each contains a number of controls, mainly images.

My question is, is there a recommended maximum size for a canvas, or is it purely a memory issue? And also, are we better off setting the Canvas size to (0, 0) and making use of the fact that we can happily render controls outside of the bounds of the canvas?

Thanks,

G

+1  A: 

From my understanding of the innards of Canvas, it should need no additional memory for being bigger.

The first thing that comes to my mind on having a non-zero sized Canvas is that it allows one to put items on it relatively to any of the four corners, which helps when e.g. resizing the container.

David Schmitt
I agree that this is correct. Silverlight only renders the visible area, so parts of your canvas that aren't visible won't be rendered and won't consume memory.
Bryant
+2  A: 

Watch out: the maximum size of a Silverlight canvas is 32767 points. This is because the size of UIElements is not stored as floats as it is in WPF, but in 32 bit quantities of which 16 bits form the integer of size and 16 bits form the floating part of it. So make sure your canvas is not bigger than that and not going to be.

The solution which you would need to make it larger is to do the scrolling yourself and position the objects yourself. In effect you're recreating the canvas. This is called Virtualizing in WPF terms.

The memory consumption won't be bigger depending on the canvas size but depend only on the number of controls and the cumulative memory size of those controls. However, if you're going to have a lot of WPF objects, the layout phase does take considerable time with more (say, more than 1000) objects. If that's going to be a problem you need to code it yourself again and have a cache of unused WPF objects of the same type lying around (since WPF object creation is also quite slow).

Rutger Nijlunsing
Hi Rutger, I've just run into the problem you described. I'm trying to draw a large chart that extends 3 or 4 times wider than 32767 pixels. The Silverlight canvas is not up to the job.Can you point me towards info on creating a virtualized canvas? Or drop me an email at [email protected] please.
Simon Brangwin