我如何移动粘贴/贴紧wpf窗口

当我移动一个“主”窗口时,我想移动两个或更多的粘性窗口

我想要做这样的事情

private void MainWindow_PreviewMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { this.DragMove(); foreach (var window in App.Current.Windows.OfType<Window>()) { window.Move(); // move it } } } 

我想用这个解决scheme来捕捉窗口

用于WPF的捕捉/粘滞/磁性窗口http://programminghacks.net/2009/10/19/download-snapping-sticky-magnetic-windows-for-wpf/

但是我怎样才能移动它?

编辑

在Gustavo Cavalcanti的回复之后,我提了几个想法。 这是我的问题的粗略解决scheme。

 using System.Windows; using System.Windows.Data; namespace DragMoveForms { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { public Window1() { this.InitializeComponent(); } public Window1(Window mainWindow) : this() { var b = new Binding("Left"); b.Converter = new MoveLeftValueConverter(); b.ConverterParameter = mainWindow; b.Mode = BindingMode.TwoWay; b.Source = mainWindow; BindingOperations.SetBinding(this, LeftProperty, b); b = new Binding("Top"); b.Converter = new MoveTopValueConverter(); b.ConverterParameter = mainWindow; b.Mode = BindingMode.TwoWay; b.Source = mainWindow; BindingOperations.SetBinding(this, TopProperty, b); } } } using System; using System.Globalization; using System.Windows; using System.Windows.Data; namespace DragMoveForms { public class MoveLeftValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // ok, this is simple, it only demonstrates what happens if (value is double && parameter is Window) { var left = (double)value; var window = (Window)parameter; // here i must check on which side the window sticks on return left + window.ActualWidth; } return 0; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return DependencyProperty.UnsetValue; } } } using System; using System.Globalization; using System.Windows; using System.Windows.Data; namespace DragMoveForms { public class MoveTopValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // ok, this is simple, it only demonstrates what happens if (value is double && parameter is Window) { var top = (double)value; var window = (Window)parameter; // here i must check on which side the window sticks on return top; } return 0; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return DependencyProperty.UnsetValue; } } } 

Solutions Collecting From Web of "我如何移动粘贴/贴紧wpf窗口"