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);
:
You need to call InitializeComponent(); before adding the shapes or it will result in the exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With