-1

When I try to get an Ellipse it does not show. I set the colour, size, and location.

Here is my current code:

public static Ellipse MainSnake = new Ellipse();

private void button_Click(object sender, RoutedEventArgs e)
{
    button.Visibility = Visibility.Hidden;

    MainSnake.Height = 10;
    MainSnake.Width = 10;
    MainSnake.Fill = Brushes.Yellow;
    Canvas.SetLeft(MainSnake, 250);
    Canvas.SetTop(MainSnake, 150);
}

When I click the button all that appears is the background.

what I am experiencing

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
asdfasdfadsf
  • 381
  • 3
  • 14

1 Answers1

2

Ellipse is a GUI object and should thus be being generated at runtime, you also need to add it to the canvas's Children collection:

private void Button_Click(object sender, RoutedEventArgs e)
{
    button.Visibility = Visibility.Hidden;

    Ellipse MainSnake = new Ellipse();
    MainSnake.Height = 10;
    MainSnake.Width = 10;
    MainSnake.Fill = Brushes.Yellow;
    Canvas.SetLeft(MainSnake, 250);
    Canvas.SetTop(MainSnake, 150);

    theCanvas.Children.Add(MainSnake);
}
Mark Feldman
  • 15,731
  • 3
  • 31
  • 58