我在 Windows 8 XAML 中实现了一个模拟拨号,它几乎可以工作
但是,当转动表盘时,它会像疯了一样摇晃。它似乎在移动时顺时针和逆时针旋转了近 90 度。我已经使用PointerPressed
,PointerReleased
和PointerMoved
我的代码
private void dial_PointerPressed(object sender, PointerRoutedEventArgs e)
{
dialPressed = true;
}
private void dial_PointerReleased(object sender, PointerRoutedEventArgs e)
{
dialPressed = false;
}
private void dial_PointerMoved(object sender, PointerRoutedEventArgs e)
{
if(dialPressed)
{
Windows.UI.Input.PointerPoint currentLocation =
e.GetCurrentPoint(dial);
Point dialCenter =
new Point(dial.ActualHeight / 2, dial.ActualWidth / 2);
double radians = Math.Atan(
(currentLocation.Position.Y - dialCenter.Y) /
(currentLocation.Position.X - dialCenter.X));
RotateTransform r = new RotateTransform();
r.Angle = radians * 180 / Math.PI;
if (currentLocation.Position.X - dialCenter.X < 0)
{
r.Angle += 180;
}
TransformGroup t = new TransformGroup();
t.Children.Add(r);
dial.RenderTransform = t;
}
}
我应该对不同的事件有约束力吗?是什么让我的表盘抖动?