我想移動兩個或兩個以上粘窗戶當我移動「主」窗口我如何可以移動粘/搶購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
}
}
}
我想使用此解決方案時用於捕捉的窗戶
捕捉/粘/窗磁爲WPF http://programminghacks.net/2009/10/19/download-snapping-sticky-magnetic-windows-for-wpf/
,但我怎麼能移動嗎?
編輯
從古斯塔沃·卡瓦爾康蒂的答覆後,我做了一些想法。這是我的問題的粗略解決方案。
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;
}
}
}
現在看起來好多了! – SvenG