You said that you have an ArrayList
of DrawingGroup
objects. When you get elements of this collection by the indexer []
(in drawingGroups[sensors-1]
), you just get an object
instead of a DrawingGroup
. You could cast the object to DrawingGroup
, but it would be better to use a strongly typed collection like List<T>
.
Just change the type of drawingGroups
to List<DrawingGroup>
:
using System.Collections.Generic;
...
var drawingGroups = new List<DrawingGroup>();
drawingGroups.Add(new DrawingGroup());
imageSources.Add(new DrawingImage(drawingGroups[sensors-1]);