请说我,如何在点击鼠标时更换命令TouchPoint?我添加了我必须更改的代码:
private Dictionary<int, UIElement> myEllipses =
new Dictionary<int, UIElement>();
private void cnv_MouseDown(object sender, MouseButtonEventArgs e)
{
Ellipse ellipse = new Ellipse();
ellipse.Width = 30;
ellipse.Height = 30;
ellipse.Stroke = Brushes.White;
ellipse.Fill = Brushes.Gold;
TouchPoint tp = e.GetPosition(cnv);
Canvas.SetTop(ellipse, tp.Bounds.Top);
Canvas.SetLeft(ellipse, tp.Bounds.Left);
myEllipses[e.TouchDevice.Id] = ellipse;
cnv.Children.Add(ellipse);
}
答案 0 :(得分:1)
尝试使用GetPosition()
方法获取点击鼠标的位置。试试这个:
private void cnv_MouseDown(object sender, MouseButtonEventArgs e)
{
Point clickedPt = e.GetPosition(this);
var xPos = clickedPt.X;
var yPos = clickedPt.Y;
}