我想将两种或两种以上粘窗户当我移动主窗口
我想要做这样的事
私人无效MainWindow_ previewMouseMove(对象发件人,发送MouseEventArgs E){
如果(e.LeftButton == MouseButtonState。pressed){
this.DragMove();
的foreach(变种窗口中App.Current.Windows.OfType&所述;窗口>()){
window.Move(); //移动
}
}
}
我想使用该解决方案为捕捉窗口
捕捉/粘/窗磁为WPF 的http://programminghacks.net/2009/10/19/download-snapping-sticky-magnetic-windows-for-wpf/
但我怎么能移动吗?
修改
在从古斯塔沃·卡瓦尔康蒂的答复,我提出了一些想法。这里是一个粗略的解决我的问题。
使用System.Windows;
使用System.Windows.Data;
命名空间DragMoveForms
{
///<总结>
///为Window1.xaml交互逻辑
///< /总结>
公共部分类窗口1:窗口
{
公共窗口1(){
this.InitializeComponent();
}
公共窗口1(窗口的主窗口)
: 本() {
变种B =新的绑定(左);
b.Converter =新MoveLeftValueConverter();
b.ConverterParameter =的主窗口;
b.Mode = BindingMode.TwoWay;
b.Source =的主窗口;
BindingOperations.SetBinding(这一点,LeftProperty,B);
B =新的绑定(顶部);
b.Converter =新MoveTopValueConverter();
b.ConverterParameter =的主窗口;
b.Mode = BindingMode.TwoWay;
b.Source =的主窗口;
BindingOperations.SetBinding(这一点,TopProperty,B);
}
}
}
使用系统;
使用System.Globalization;
使用System.Windows;
使用System.Windows.Data;
命名空间DragMoveForms
{
公共类MoveLeftValueConverter:的IValueConverter
{
公共对象转换(对象的值,类型TARGETTYPE,对象参数,CultureInfo的文化){
// OK,这很简单,它只是表明会发生什么
如果(值是双倍和放大器;&放大器;参数是窗口){
VAR左=(双)值;
VAR窗口=(窗口)参数;
//这里我必须检查窗枝哪一边
返回左+ window.ActualWidth;
}
返回0;
}
公共对象ConvertBack(对象的值,类型TARGETTYPE,对象参数,CultureInfo的文化){
返回DependencyProperty.UnsetValue;
}
}
}
使用系统;
使用System.Globalization;
使用System.Windows;
使用System.Windows.Data;
命名空间DragMoveForms
{
公共类MoveTopValueConverter:的IValueConverter
{
公共对象转换(对象的值,类型TARGETTYPE,对象参数,CultureInfo的文化){
// OK,这很简单,它只是表明会发生什么
如果(值是双倍和放大器;&放大器;参数是窗口){
VAR顶=(双)值;
VAR窗口=(窗口)参数;
//这里我必须检查窗枝哪一边
返回顶部;
}
返回0;
}
公共对象ConvertBack(对象的值,类型TARGETTYPE,对象参数,CultureInfo的文化){
返回DependencyProperty.UnsetValue;
}
}
}
解决方案
使用数据窗口的左侧,顶部具有约束力。使用转换器,以确定正确的左/上基于主窗口。然后,只是担心移动的主要窗口,是其他人将相应地移动。
i want move two or more sticky windows when i move a "main" window
i want 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 use this solution for snapping the 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 the reply from Gustavo Cavalcanti, i made a few thoughts. Here is a rough 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;
}
}
}
解决方案
Use data binding on the Left and Top of the windows. Use converters to determine the right left/top based on the main window. Then just worry about moving the main window, that the others will move accordingly.