我正在尝试从我的鼠标位置向我的网格添加一个椭圆。如何定义椭圆的绘制位置?
这是我的鼠标按下事件:
private void GridCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_sensorPoint = Mouse.GetPosition(GridCanvas);
AddSensor();
}
还有我的 AddSensor() 方法:
private void AddSensor()
{
Ellipse sensorEllipse = new Ellipse();
SolidColorBrush solidColorBrush = new SolidColorBrush();
solidColorBrush.Color = Color.FromArgb(0, 0, 0, 0);
sensorEllipse.Fill = solidColorBrush;
sensorEllipse.StrokeThickness = 2;
sensorEllipse.Stroke = Brushes.Black;
sensorEllipse.Width = 10;
sensorEllipse.Height = 10;
GridCanvas.Children.Add(sensorEllipse);
}
如何在画布上单击鼠标的位置添加 sensorEllipse?