private void Button_Click(object sender, RoutedEventArgs e) { MyBox box = new MyBox { Header = "Another box", Text = "...", BorderBrush = Brushes.Black, BorderThickness = new Thickness(1), Margin = new Thickness(10) }; box.MouseLeftButtonDown += Box_MouseLeftButtonDown; box.MouseLeftButtonUp += Box_MouseLeftButtonUp; box.MouseMove += Box_MouseMove; panel.Children.Add(box); }
private void Box_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { draggedBox.ReleaseMouseCapture(); draggedBox = null; }
private void Box_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { draggedBox = sender as MyBox; clickPosition = e.GetPosition(draggedBox); draggedBox.CaptureMouse(); }