How can I move sticky / anchor wpf windows

I want to move two or more sticky windows when I go to the main window

I want to do something like this

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 } } } 

I want to use this solution to bind windows

Snapping / Sticky / Magnetic Windows for WPF http://programminghacks.net/2009/10/19/download-snapping-sticky-magnetic-windows-for-wpf/

but how can i move it?

EDIT

After Gustavo Cavalcanti answered, I made a few thoughts. Here is a rude solution to my question.

 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; } } } 
+4
source share
1 answer

Use the data binding on the left and top of the windows. Use the transducers to determine the right left / top position based on the main window. Then just worry about moving the main window so that others move accordingly.

+5
source

Source: https://habr.com/ru/post/1381800/


All Articles