Tips for creating massive amounts of shapes

I am often asked how to reduce the creation time for a massive number of shapes.


Try a few things:

1)      Use XamlReader.Load when you can (with the mini-language), which allows you to use the native parser and not managed code to create new shapes

2)      Use the mini-language for Paths or lines (whether using Xamlreader or C#) – both Silverlight and WPF optimize the mini-language internally, in different ways. When the mini-language is used, Silverlight does not create managed object for each PathFigure, Point etc– which saves creation time and space:


3)      Switch to Bitmaps if appropriate.

4)      Prototype! Prototype! Prototype! Don't write everything and realize that SL can't generate 100,000 managed objects every 10msec. =)


Generally, for drawing massive number of shapes, you want to reduce the amount of time spent in managed creation time.


Comments (5)

  1. EugenRata says:

    Well, no body is expecting to paint 100,000 objects. I would be happy if SL | WPF would paint 2000 rectangles at least with a reasonable speed.

    I could achieve this using Path and Geometries + XamlReader, but the problem here is I can’t set the gradient Brush for each rectangle. So, I’m back to my issue.

    Any idea?

    Just show me a simple sample (WPF is fine, but must be compatible with SL) that paints 2000 rectangles each with a gradient and when you resize the window it will repaint and scale immediatly all the rectangles.

    I bet $100 that at least 100 developers would like to see such a sample!


  2. Gongdo says:

    Also IsHitTestVisible="False" will increase graphic performance after objects loaded, if objects don’t need to interact with user.

    However I’m not sure whether it could reduce amount of creating time or not. How is it, Seema?

  3. SharpGIS says:

    Regarding #2, how would I set the data on an path geometry?

    The following throws throws an ArgumentException:

    myPath.SetValue(Path.DataProperty, "M 10,100 C 10,300 300,-200 300,100");

  4. EugenRata says:

    yeah, you can’t set the Path value as a string in Silverlight.

    However it works correctly in WPF.

    Any idea Seema?

Skip to main content