2011-11-17 1 views
4

내가나는 끈적 끈적한/스냅 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 
    } 
    } 
} 

같은 일을하고자하는 "기본"창을 이동할 때 내가이 솔루션을 사용하려면 두 개 이상의 끈끈한 창을 이동하려면 이동할 수있는 방법 http://programminghacks.net/2009/10/19/download-snapping-sticky-magnetic-windows-for-wpf/

하지만 난 그것을 어떻게 이동할 수 있습니다 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; 
    } 
    } 
} 
+0

훨씬 나아졌습니다! – SvenG

답변

5

창의 왼쪽과 위쪽에서 데이터 바인딩을 사용하십시오. 변환기를 사용하여 기본 창을 기준으로 오른쪽/왼쪽을 결정합니다. 그런 다음 메인 윈도우를 움직이는 것에 대해 걱정하고, 다른 사람들은 그에 따라 이동할 것입니다.

+0

고맙습니다. 내 편집 된 질문을보세요 – punker76

+0

솔루션이 작동하므로 고맙습니다. 주 창의 크기는 어떻게됩니까? 너비 변경시, 여전히 LeftProperty를 수정할 수 있습니까? – Li3ro