我正在使用MouseLeftButtonDown
,MouseMove
和MouseLeftButtonUp
移動WP7中的按鈕。問題是,當我移動它(通過鼠標)它看起來不穩定,我無法解釋它。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;
}
我做錯了什麼?提前致謝!
您應該使用ManipulationDelta事件。該事件爲您提供自上次事件觸發以來鼠標移動了多少像素。然後,您可以將此值添加到控件的當前邊距。 – 2012-02-06 13:13:17