I´m new to C# and also WPF. Im playing around with Canvas and Ellipses and stuff.
I created a method to create a new canvas:
public void CreateCanvas(Canvas parentCanvas, int height, int width, double xCoord, double yCoord)
{
Canvas new_canvas = new Canvas();
new_canvas.Background = new SolidColorBrush(Colors.Red);
new_canvas.Height = height;
new_canvas.Width = width;
Canvas.SetLeft(new_canvas, xCoord);
Canvas.SetTop(new_canvas, yCoord);
parentCanvas.Children.Add(new_canvas);
}
When I, for example, want to add another child to a canvas, created this way, I need the name of the canvas. So my guess is to make the canvas name a parameter also. Well.. no clue how to.
I want it to look like this.
public void CreateCanvas(Canvas parentCanvas, string canvasName, int height, int width, double xCoord, double yCoord)
{
Canvas canvasName = new Canvas();
canvasName.Background = new SolidColorBrush(Colors.Red);
canvasName.Height = height;
canvasName.Width = width;
Canvas.SetLeft(canvasName, xCoord);
Canvas.SetTop(canvasName, yCoord);
parentCanvas.Children.Add(canvasName);
}
What I want to do is to add a textblock as a child (Children.Add) to the canvas i created by the method, after the canvas is allready created.