当我尝试获取Ellipse时,它没有显示。我设置颜色,大小和位置。
这是我目前的代码:
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);
}
当我点击按钮时,所有出现的背景都是背景。
答案 0 :(得分:2)
Ellipse是一个GUI对象,因此应该在运行时生成,您还需要将它添加到画布的子集合中:
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);
}