code_junkie

Lazy initialization causing System.ArgumentException in Silverlight 2.0 beta

Nov 11th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public Page()
  2. {
  3. InitializeComponent();
  4. InitializeOther();
  5. }
  6.  
  7. private DoubleCollection dashes;
  8.  
  9. public DoubleCollection Dashes
  10. {
  11. get
  12. {
  13. //dashes = new DoubleCollection(); //works ok
  14. //dashes.Add(2.0);
  15. //dashes.Add(2.0);
  16.  
  17. if (dashes == null)
  18. {
  19. dashes = new DoubleCollection(); //causes exception
  20. dashes.Add(2.0);
  21. dashes.Add(2.0);
  22. }
  23. return dashes;
  24. }
  25. set
  26. {
  27. dashes = value;
  28. }
  29. }
  30.  
  31. private void InitializeOther()
  32. {
  33. Line line;
  34. for (int i = 0; i < 10; i++)
  35. {
  36. line = new Line();
  37. line.Stroke = new SolidColorBrush(Colors.Blue);
  38. line.StrokeDashArray = Dashes; //exception thrown here
  39. line.X1 = 10;
  40. line.Y2 = 10;
  41. line.X2 = 400;
  42. line.Y2 = 10 + (i * 40);
  43. canvas1.Children.Add(line);
  44. }
  45. }
  46.  
  47. line = new Line();
  48. line.Stroke = new SolidColorBrush(Colors.Blue);
  49. line.StrokeDashArray = **new DoubleCollection() { 2.0, 2.0 };**
  50. line.X1 = 10;
  51. ...
Add Comment
Please, Sign In to add comment