开发者

How can a method in C# be used in XAML?

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 c开发者_C百科lass MainWindow : Window
{
    public Window()
    {
      InitializeComponent();

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

     }
}


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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜