문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top