Reputation: 67
I've been successful at placing an ellipse on a canvas, but it shows up at the top left corner of it despite my trying different methods of moving it. In this attempt, I am trying to move it to the center of the canvas, but I would like to be able to move it anywhere in the canvas.
private Ellipse drawEllipse(Canvas aCanvas)
{
Ellipse newEllipse= new Ellipse();
newEllipse.Width = 40;
newEllipse.Height = 40;
newEllipse.Fill = new SolidColorBrush(Colors.Aquamarine);
aCanvas.Children.Add(lEllipse);
newEllipse.SetValue(Canvas.LeftProperty, aCanvas.ActualWidth / 2.0);
newEllipse.SetValue(Canvas.TopProperty, aCanvas.ActualHeight / 2.0);
return newEllipse;
}
Upvotes: 2
Views: 4837
Reputation: 101
Try this:
Canvas.SetLeft(newEllipse, aCanvas.ActualWidth/2.0);
Canvas.SetTop(newEllipse, aCanvas.ActualHeight/2.0);
I didn't try it, but it worked for me all the time.
Edit: Ahh and you should probably first add the ellipse to the canvas before moving the ellipse around.
Upvotes: 4