Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding shapes to Grid in Silverlight with C#

I am trying to add a shape to a Silverlight 5 project in Visual Studio 2012. I have been able to add a shape using XAML, but I would like to do it with C#.

I have tried using example code from this tutorial.

I have in MainPage.xaml the following line: <Grid x:Name="LayoutRoot" Background="White" Margin="10,0,0,0" />

Then, I have put his CreateARectangle() method in MainPage.xaml.cs. I have put my complete code here: http://pastebin.com/up1NtfE5

I currently get no error upon building. When I launch the page in the browser, it simply circles loading at 100% indefinitely. The plug-in does work, however, as it worked when I tried to make the same object with XAML.

Any help would be appreciated, as well as possibly better resources to accomplish this.

Update: When I switched to debugging with IE instead of Firefox, I got this additional information at the line LayoutRoot.Children.Add(blueRectangle);: enter image description here

like image 794
Jake Avatar asked Sep 30 '14 17:09

Jake


1 Answers

You need to call InitializeComponent(); before adding the shapes or it will result in the exception.

like image 153
Keith R Avatar answered Oct 19 '22 13:10

Keith R