共用方式為


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:

https://msdn.microsoft.com/en-us/library/cc189041(VS.95).aspx

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.

-Seema

Comments

  • Anonymous
    May 28, 2009
    PingBack from http://microsoft-sharepoint.simplynetdev.com/tips-for-creating-massive-amounts-of-shapes/

  • Anonymous
    May 29, 2009
    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! Thx

  • Anonymous
    May 29, 2009
    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?

  • Anonymous
    June 06, 2009
    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");

  • Anonymous
    June 09, 2009
    yeah, you can't set the Path value as a string in Silverlight. However it works correctly in WPF. Any idea Seema?