我想使用MouseLeftButtonDown
,MouseMove
和MouseLeftButtonUp
在WP7中移动按钮。问题是,当我移动它(通过鼠标)它看起来不稳定,我无法解释它。
bool clicked = false;
private void button1_MouseMove(object sender, MouseEventArgs e)
{
Point p = e.GetPosition(sender as Button);
double margin1, margin2;
margin1 = p.X - (button1.ActualWidth / 2) + 12;
// 12 is the distance between left of the page and the content panel
margin2 = p.Y - (button1.ActualHeight / 2) + 161;
// 161 is the distance between top of the page and the content panel
button1.Margin = new Thickness(margin1, margin2, 0, 0);
}
private void button1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
clicked = true;
}
private void button1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
clicked = false;
}
我做错了吗?提前谢谢!