Hello!
I've got the following example running in a simple Silverlight page:
public Page()
{
InitializeComponent();
InitializeOther();
}
private DoubleCollection dashes;
public DoubleCollection Dashes
{
get
{
//dashes = new DoubleCollection(); //works ok
//dashes.Add(2.0);
//dashes.Add(2.0);
if (dashes == null)
{
dashes = new DoubleCollection(); //causes exception
dashes.Add(2.0);
dashes.Add(2.0);
}
return dashes;
}
set
{
dashes = value;
}
}
private void InitializeOther()
{
Line line;
for (int i = 0; i < 10; i++)
{
line = new Line();
line.Stroke = new SolidColorBrush(Colors.Blue);
line.StrokeDashArray = Dashes; //exception thrown here
line.X1 = 10;
line.Y2 = 10;
line.X2 = 400;
line.Y2 = 10 + (i * 40);
canvas1.Children.Add(line);
}
}
The above code throws a System.ArgumentException on the line marked. One solution to the problem is also marked in the example.
Does anybody know if this problem is related to the fact that the property System.Windows.Shapes.Shape.StrokeDashArray is a dependency property?
Many thanks for any hints!