Pergunta

I have the following code that is the addrange method:

foreach (var graphic in buffersList)
{
    if (!graphicsLayerHeat.Graphics.Contains(graphic))
    {
       graphicsLayerHeat.Graphics.AddRange(buffersList);  
    }
}

But the visual studio prompts me this error

'ESRI.ArcGIS.Client.GraphicCollection' does not contain a definition for 'AddRange' and no extension method 'AddRange' accepting a first argument of type 'ESRI.ArcGIS.Client.GraphicCollection' could be found (are you missing a using directive or an assembly reference?)

How can I change the method so that it can work the same way without using addrange?

Foi útil?

Solução

Change this

graphicsLayerHeat.Graphics.AddRange(buffersList);  

to this:

graphicsLayerHeat.Graphics.Add(graphic);  

I assume you don't want to add the bufferlist over and over again (as the other answerer's solution would do).

The newer version of the ESRI silverlight API does have an AddRange method (time to update?), but I don't think that's what you want to use since you also want to do the contains check.

Outras dicas

Just use a foreach loop to add the items manually

foreach (var buffer in buffersList) {
 graphicsLayerHeat.Graphics.Add(buffer);
}

If this is a common operation you may just want to create an AddRange extension method yourself

static void AddRange(this GraphicsCollection source, GraphicsCollection list) {
  foreach (var item it list) { 
    source.Add(item);
  }
}

It's possible this could be made more general but I'm unfamiliar with the GraphicsCollection type so I don't know what interfaces it implements

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top