Creating a Box outside of .xaml - WP7 :: Please!? ::

Oct 8, 2011 at 8:31 PM
Edited Oct 11, 2011 at 6:19 PM

I created a Project and everything works fine. I can see all my Boxes i created in the xaml.

Now i tried to add a Box using C# in MainPage.xaml.cs 

The code i used for that is:

public void draw234_Click(object sender, RoutedEventArgs e)
            Random a = new Random();
            Game.Children.Add(new Balder.Objects.Geometries.Box()
                Dimension = new Balder.Math.Coordinate(10, 10, 10),
                Position = new Balder.Math.Coordinate(a.Next(15, 25), 0, a.Next(15, 25)),
                Name = a.Next().ToString()

My code in the xaml is:

 <Execution:Game x:Name="Game" Width="800" Height="480" Background="Blue">
                <View:Camera x:Name="PlayersView" Position="-60,30,-60" Target="20,0,20"/>
            <Geometries:Box x:Name="box" Dimension="10,10,10" Position="0,0,0" Color="Red"/>

Im a really newbe about this and i would be happy, if you could tell me what im doing wrong.
Nov 29, 2011 at 9:03 AM
Edited Nov 29, 2011 at 9:05 AM


You need to replace the line Game.Children.Add(...) with the the following:

Game.Scene.AddNode(new Balder.Objects.Geometries.Box() ...

Hope this helps.