using System.Windows;using System.Windows.Controls;using System.Windows.Input;
namespace ButtonSpeedTest{ public partial class Window1 : Window { bool isDragging;
public Window1() { InitializeComponent(); }
private void MyMouseDown(object sender, MouseButtonEventArgs e) { isDragging = true; }
private void MyMouseUp(object sender, MouseButtonEventArgs e) { isDragging = false; }
private void MyMouseMove(object sender, MouseEventArgs e) { if (isDragging) { Point position = e.GetPosition(this);
rect.SetValue(Canvas.LeftProperty, position.X - rect.Width / 2); rect.SetValue(Canvas.TopProperty, position.Y - rect.Height / 4); } } }}