提问:如何消除silverlight移动图形时虚影的问题
对silverlight学习中遇到了一个问题,完成移动图形时,当鼠标移动过快,会出现虚影的问题,感觉应该是由于OnMouseMove太过频繁的原因,怎么可以改进呢?
private void onMouseDow(object sender, MouseButtonEventArgs e)
{
FrameworkElement element = sender as FrameworkElement;
mousePosition = e.GetPosition(null);
IsMouseDown = true;
if (element != null)
{
element.CaptureMouse();
element.Cursor = Cursors.Hand;
}
}
private void onMouseMove(object sender, MouseEventArgs e)
{
FrameworkElement element = sender as FrameworkElement;
if (IsMouseDown)
{
double varX = e.GetPosition(null).X - mousePosition.X;
double varY = e.GetPosition(null).Y - mousePosition.Y;
double newTop = varY + (double)element.GetValue(Canvas.TopProperty);
double newLef = varX + (double)element.GetValue(Canvas.LeftProperty);
element.SetValue(Canvas.TopProperty, newTop);
element.SetValue(Canvas.LeftProperty, newLef);
mousePosition = e.GetPosition(null);
}
}
private void onMouseUp(object sender, MouseButtonEventArgs e)
{
FrameworkElement element = sender as FrameworkElement;
IsMouseDown = false;
mousePosition.X = mousePosition.Y = 0;
element.Cursor = Cursors.Arrow;
element.ReleaseMouseCapture();
}