tags:

views:

64

answers:

2

I have a method creating a cone, such as in the following code snippet.

Could you explain me how this cone created by CreateCone(...) can be used in a XAML file in the same solution.

C# Code snippet :

public partial class MainWindow : Window
{
    public Window()
    {
      InitializeComponent();

      CreateCone(new Point3D(0, 0, 0), 0, 0.025, 0.1, 100, Colors.Red);         

     }
}
+1  A: 

Depends when/where you want the method fired. You could call the method from a Grid event, etc. Not really sure why you would want to do that though.

Ie. <Grid Loaded="CreateConeWrapper" />, and the wrapper would call the CreateCone() function.

Mark Kadlec
Well if you had a button that said "Create Cone" you could have this as the `MouseClick` event handler.
ChrisF
Absolutely. My Grid event was purely an example of an event on a control, happened to be the first that popped into my head. Mouseclick is a much more common one for sure!
Mark Kadlec
+1  A: 

If you give XAML objects a name like this:

<canvas name="myCanvas"></canvas>

Then you can access them from the code behind file using that name. Depending on the type of control it is you can usually either set the Content property, or add stuff to the controls Children collection:

myCanvas.Children.Add(mycreatedCode);
Simon P Stevens