public BindingPosition GetPositionOfCommonButton( IWindowElement master, IWindowElement slave )
        {
            UnbindButtonContainer m = _unbindButtonContainers[master];
            UnbindButtonContainer s = _unbindButtonContainers[slave];

            if( m.TopButton != null && s.BottomButton != null && m.TopButton == s.BottomButton ) return BindingPosition.Top;
            if( m.RightButton != null && s.LeftButton != null && m.RightButton == s.LeftButton ) return BindingPosition.Right;
            if( m.LeftButton != null && s.RightButton != null && m.LeftButton == s.RightButton ) return BindingPosition.Left;
            if( m.BottomButton != null && s.TopButton != null && m.BottomButton == s.TopButton ) return BindingPosition.Bottom;
            return BindingPosition.None;
        }
Exemplo n.º 2
0
        void IBrowserDriver.SwitchToWindow <T>(IWindowElement <T> seleniumWindowElement)
        {
            var windowCount = seleniumDriver.WindowHandles.Count();

            Wait.WithRetry().Doing(() => seleniumWindowElement.Click()).Until(() => seleniumDriver.WindowHandles.Count() > windowCount);

            var mostRecentWindow = seleniumDriver.WindowHandles.LastOrDefault();

            if (mostRecentWindow != default(string))
            {
                seleniumDriver.SwitchTo().Window(mostRecentWindow);
            }
        }
Exemplo n.º 3
0
        protected virtual void OnWindowGotFocus( object sender, EventArgs e )
        {
            if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread. Call OnWindowGotFocus to make sure the correct thread carries on." );

            IWindowElement windowElement = sender as IWindowElement;
            if( windowElement != null )
            {
                WindowElementData data = null;
                if( _dic.TryGetValue( windowElement, out data ) )
                {
                    _lastFocused = windowElement;
                    if( WindowGotFocus != null )
                        WindowGotFocus( sender, new WindowElementEventArgs( windowElement ) );
                }
            }
        }
Exemplo n.º 4
0
        public virtual IManualInteractionResult Resize( IWindowElement window, double width, double height )
        {
            if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." );

            WindowElementData data = null;
            if( _dic.TryGetValue( window, out data ) )
            {
                WindowElementData cloneData = (WindowElementData)data.Clone();
                window.Resize( width, height );

                return new ResizeResult( this, data, cloneData );
            }
            return NullResult.Default;
        }
Exemplo n.º 5
0
        public virtual IManualInteractionResult Move( IWindowElement window, double top, double left )
        {
            if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." );

            WindowElementData data = null;
            if( _dic.TryGetValue( window, out data ) )
            {
                WindowElementData dataSnapshot = (WindowElementData)data.Clone();

                window.Move( top, left );

                return new MoveResult( this, data, dataSnapshot );
            }
            return NullResult.Default;
        }
 public UnbindButtonContainer( IWindowElement window )
 {
     Window = window;
 }
        WindowElement InitializeButton( IWindowElement window, IWindowElement other, BindingPosition position )
        {
            Debug.Assert( Dispatcher.CurrentDispatcher == NoFocusManager.Default.ExternalDispatcher, "This method should only be called by the ExternalThread." );
            WindowElement button = null;

            button = new WindowElement( new UnbindButtonView()
            {
                DataContext = CreateVM( window, other, position )
            }, "UnbindButton" );

            DoPlaceButtons( button, window, position );

            TopMostService.Service.RegisterTopMostElement( "30", button.Window );

            return button;
        }
        void FillContainers( IWindowElement master, IWindowElement slave, BindingPosition position )
        {
            UnbindButtonContainer masterContainer;
            UnbindButtonContainer slaveContainer;

            if( !_unbindButtonContainers.TryGetValue( slave, out slaveContainer ) )
            {
                slaveContainer = new UnbindButtonContainer( slave );
                _unbindButtonContainers.Add( slave, slaveContainer );
            }
            if( !_unbindButtonContainers.TryGetValue( master, out masterContainer ) )
            {
                masterContainer = new UnbindButtonContainer( master );
                _unbindButtonContainers.Add( master, masterContainer );
            }

            Debug.Assert( masterContainer.GetUnbindFromPosition( position ) == null );
            Debug.Assert( slaveContainer.GetUnbindFromPosition( GetOppositePosition( position ) ) == null );

            IWindowElement button = InitializeButton( master, slave, position );

            masterContainer.SetButton( button, position );
            slaveContainer.SetButton( button, GetOppositePosition( position ) );

            button.Show();
            EnableUnbindButtons();
        }
        public ISpatialBinding GetBinding( IWindowElement referential )
        {
            if( referential == null ) throw new ArgumentNullException( "referential" );

            SpatialBinding b = null;
            _spatialBindings.TryGetValue( referential, out b );
            return b ?? new SpatialBinding( referential );
        }
Exemplo n.º 10
0
        public void Bind( IWindowElement master, IWindowElement slave, BindingPosition position, bool saveBinding = false )
        {
            if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." );

            if( master == null ) throw new ArgumentNullException( "master" );
            if( slave == null ) throw new ArgumentNullException( "slave" );

            //Console.WriteLine( "BIND thread id: {0} TimeSpan : {1}", Thread.CurrentThread.ManagedThreadId, DateTime.Now.Ticks );

            // Spatial binding point of view
            using( _logger.OpenGroup( LogLevel.Info, "Attaching {0} on {1} at {2}", master.Name, slave.Name, position.ToString() ) )
            {
                SpatialBinding spatialBinding = null;
                SpatialBinding slaveSpatialBinding = null;

                if( CanBind( master, slave, position, out spatialBinding, out slaveSpatialBinding ) )
                {
                    _logger.Trace( "Before binding..." );

                    var binding = new SimpleBinding
                    {
                        Target = master,
                        Origin = slave,
                        Position = position
                    };

                    var evt = new WindowBindingEventArgs
                    {
                        Binding = binding,
                        BindingType = BindingEventType.Attach
                    };

                    if( BeforeBinding != null )
                        BeforeBinding( this, evt );

                    if( evt.Canceled == true )
                    {
                        _logger.Trace( "...canceled. The reason was {0}.", evt.CancelReason ?? "No Reason" );
                    }
                    else
                    {
                        if( spatialBinding == null )
                        {
                            spatialBinding = new SpatialBinding( master );
                            _spatialBindings.Add( master, spatialBinding );
                        }
                        if( slaveSpatialBinding == null )
                        {
                            slaveSpatialBinding = new SpatialBinding( slave );
                            _spatialBindings.Add( slave, slaveSpatialBinding );
                        }

                        Debug.Assert( spatialBinding != null );
                        Debug.Assert( slaveSpatialBinding != null );

                        //TODO : FIXWITHDOCKING

                        if( position == BindingPosition.Top )
                        {
                            spatialBinding.Top = slaveSpatialBinding;
                            slaveSpatialBinding.Bottom = spatialBinding;
                        }
                        if( position == BindingPosition.Left )
                        {
                            spatialBinding.Left = slaveSpatialBinding;
                            slaveSpatialBinding.Right = spatialBinding;
                        }
                        if( position == BindingPosition.Bottom )
                        {
                            spatialBinding.Bottom = slaveSpatialBinding;
                            slaveSpatialBinding.Top = spatialBinding;
                        }
                        if( position == BindingPosition.Right )
                        {
                            spatialBinding.Right = slaveSpatialBinding;
                            slaveSpatialBinding.Left = spatialBinding;
                        }

                        if( saveBinding )
                            _persistantBindings.Add( binding );

                        var evtAfter = new WindowBindedEventArgs
                        {
                            Binding = binding,
                            BindingType = BindingEventType.Attach
                        };

                        _logger.Trace( "After binding..." );
                        if( AfterBinding != null )
                            AfterBinding( this, evtAfter );
                    }
                }
            }
        }
Exemplo n.º 11
0
 public void AddChild(IWindowElement child)
 {
     ChildreElements.Add(child);
 }
 public WindowElementResizeEventArgs( IWindowElement window, double deltaWidth, double deltaHeight )
     : base(window)
 {
     DeltaWidth = deltaWidth;
     DeltaHeight = deltaHeight;
 }
 public WindowElementLocationEventArgs( IWindowElement window, double deltaTop, double deltaLeft )
     : base(window)
 {
     DeltaTop = deltaTop;
     DeltaLeft = deltaLeft;
 }
 public WindowElementEventArgs( IWindowElement window )
 {
     Window = window;
 }
Exemplo n.º 15
0
 //public HitTestResult( IWindowElement windowElement, IWindowElement matchedWindow, Rect enlargedRectangle, Rect overlapRectangle )
 //{
 //    Target = windowElement;
 //    Origin = matchedWindow;
 //    if( overlapRectangle.Bottom == enlargedRectangle.Bottom && overlapRectangle.Height != enlargedRectangle.Height ) Position = BindingPosition.Top;
 //    else if( overlapRectangle.Top == enlargedRectangle.Top && overlapRectangle.Height != enlargedRectangle.Height ) Position = BindingPosition.Bottom;
 //    else if( overlapRectangle.Right == enlargedRectangle.Right && overlapRectangle.Width != enlargedRectangle.Width ) Position = BindingPosition.Left;
 //    else if( overlapRectangle.Left == enlargedRectangle.Left && overlapRectangle.Width != enlargedRectangle.Width ) Position = BindingPosition.Right;
 //    else Position = BindingPosition.None;
 //}
 public HitTestResult( IWindowElement origin, IWindowElement target, BindingPosition position )
 {
     Target = target;
     Origin = origin;
     Position = position;
 }
Exemplo n.º 16
0
 private static Rect GetIntersectionArea( ISpatialBinding binding, IDictionary<IWindowElement, Rect> setToChallenge, Rect rect, ref Rect enlargedRectangle, out IWindowElement otherWindow )
 {
     ICollection<IWindowElement> boundWindows = binding.AllDescendants().Select( x => x.Window ).ToArray();
     otherWindow = null;
     Rect rectWindow = setToChallenge[binding.Window];
     foreach( var item in setToChallenge )
     {
         otherWindow = item.Key;
         // If in all registered windows a window intersect with the one that moved
         if( otherWindow != binding.Window && !boundWindows.Contains( otherWindow ) )
         {
             rect = setToChallenge[otherWindow];
             if( !rectWindow.IntersectsWith( rect ) && rect.IntersectsWith( enlargedRectangle ) ) return Rect.Intersect( enlargedRectangle, rect );
         }
     }
     return Rect.Empty;
 }
Exemplo n.º 17
0
        void DoPlaceButtons( IWindowElement button, IWindowElement window, BindingPosition position )
        {
            Debug.Assert( Dispatcher.CurrentDispatcher == NoFocusManager.Default.ExternalDispatcher, "This method should only be called by the ExternalThread." );

            double top = window.Top;
            double height = window.Height;
            double width = window.Width;
            double left = window.Left;

            if( position == BindingPosition.Top )
            {
                button.Window.Top = top - button.Height / 2;
                button.Window.Left = left + width / 2 - button.Width / 2;
            }
            else if( position == BindingPosition.Bottom )
            {
                button.Window.Top = top + height - button.Height / 2;
                button.Window.Left = left + width / 2 - button.Width / 2;
            }
            else if( position == BindingPosition.Right )
            {
                button.Window.Top = top + height / 2 - button.Height / 2;
                button.Window.Left = left + width - button.Width / 2;
            }
            else if( position == BindingPosition.Left )
            {
                button.Window.Top = top + height / 2 - button.Width / 2;
                button.Window.Left = left - button.Height / 2;
            }
        }
Exemplo n.º 18
0
        public IBindResult PreviewBind( IWindowElement target, IWindowElement origin, BindingPosition position )
        {
            if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." );

            if( target == null ) throw new ArgumentNullException( "master" );
            if( origin == null ) throw new ArgumentNullException( "slave" );

            SpatialBinding targetSpatialBinding = null;
            SpatialBinding originSpatialBinding = null;

            if( CanBind( target, origin, position, out targetSpatialBinding, out originSpatialBinding ) )
            {
                var binding = new SimpleBinding
                {
                    Target = target,
                    Origin = origin,
                    Position = position
                };

                var evt = new WindowBindedEventArgs
                {
                    Binding = binding,
                    BindingType = BindingEventType.Attach
                };

                if( PreviewBinding != null )
                    PreviewBinding( this, evt );

                return new BindResult( this, binding );
            }
            return NullResult.Default;
        }
Exemplo n.º 19
0
 void HideButtons( IWindowElement window )
 {
     if( _unbindButtonContainers.ContainsKey( window ) )
     {
         _windowMoved = true;
         ISpatialBinding binding = WindowBinder.Service.GetBinding( window );
         foreach( var b in binding.AllDescendants() ) _unbindButtonContainers[b.Window].HideButtons();
     }
 }
Exemplo n.º 20
0
        public IBindResult PreviewUnbind( IWindowElement target, IWindowElement origin )
        {
            if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." );

            var binding = new SimpleBinding
            {
                Target = target,
                Origin = origin
            };

            var evt = new WindowBindedEventArgs
            {
                Binding = binding,
                BindingType = BindingEventType.Detach
            };

            if( PreviewBinding != null )
                PreviewBinding( this, evt );

            return new UnbindResult( this, binding );
        }
Exemplo n.º 21
0
        void RemoveButton( IWindowElement master, IWindowElement slave )
        {
            if( _unbindButtonContainers.ContainsKey( slave ) && _unbindButtonContainers.ContainsKey( master ) )
            {
                BindingPosition position = GetPositionOfCommonButton( master, slave );
                if( position != BindingPosition.None )
                {
                    _unbindButtonContainers[master][position].Close();
                    _unbindButtonContainers[master][position] = null;
                    _unbindButtonContainers[slave][GetOppositePosition( position )] = null;
                }

                CleanUnbindButtonContainers( master );
                CleanUnbindButtonContainers( slave );
            }
        }
Exemplo n.º 22
0
        public void Unbind( IWindowElement me, IWindowElement other, bool saveBinding = true )
        {
            if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." );

            if( me == null ) throw new ArgumentNullException( "me" );
            if( other == null ) throw new ArgumentNullException( "other" );

            SpatialBinding spatialBinding = null;
            if( _spatialBindings.TryGetValue( me, out spatialBinding ) )
            {
                var binding = new SimpleBinding
                {
                    Target = me,
                    Origin = other
                };
                var evt = new WindowBindingEventArgs { Binding = binding, BindingType = BindingEventType.Detach };
                if( BeforeBinding != null ) BeforeBinding( this, evt );

                if( evt.Canceled == false )
                {
                    Debug.Assert( me == spatialBinding.Window );

                    if( spatialBinding.Bottom != null && spatialBinding.Bottom.Window == other )
                    {
                        //UnbindButtonManager.Service.RemoveButton( spatialBinding.Bottom.UnbindButton );
                        spatialBinding.Bottom = null;
                        Unbind( other, me, saveBinding );
                    }
                    if( spatialBinding.Left != null && spatialBinding.Left.Window == other )
                    {
                        //UnbindButtonManager.Service.RemoveButton( spatialBinding.Left.UnbindButton );
                        spatialBinding.Left = null;
                        Unbind( other, me, saveBinding );
                    }
                    if( spatialBinding.Top != null && spatialBinding.Top.Window == other )
                    {
                        //UnbindButtonManager.Service.RemoveButton( spatialBinding.Top.UnbindButton );
                        spatialBinding.Top = null;
                        Unbind( other, me, saveBinding );
                    }
                    if( spatialBinding.Right != null && spatialBinding.Right.Window == other )
                    {
                        //UnbindButtonManager.Service.RemoveButton( spatialBinding.Right.UnbindButton );
                        spatialBinding.Right = null;
                        Unbind( other, me, saveBinding );
                    }

                    if( spatialBinding.IsAlone )
                        _spatialBindings.Remove( me );

                    if( !saveBinding )
                        _persistantBindings.Remove( binding );
                }

                var evtAfter = new WindowBindedEventArgs { Binding = binding, BindingType = BindingEventType.Detach };
                if( AfterBinding != null ) AfterBinding( this, evtAfter );
            }
        }
Exemplo n.º 23
0
 public void SetButton( IWindowElement button, BindingPosition position )
 {
     Debug.Assert( position != BindingPosition.None );
     if( position == BindingPosition.Top ) TopButton = button;
     else if( position == BindingPosition.Bottom ) BottomButton = button;
     else if( position == BindingPosition.Left ) LeftButton = button;
     else if( position == BindingPosition.Right ) RightButton = button;
 }
Exemplo n.º 24
0
        private bool CanBind( IWindowElement target, IWindowElement origin, BindingPosition position, out SpatialBinding targetSpatialBinding, out SpatialBinding originSpatialBinding )
        {
            Debug.Assert( Dispatcher.CurrentDispatcher == Application.Current.Dispatcher, "This method should only be called by the Application Thread." );

            originSpatialBinding = null;
            using( _logger.OpenGroup( LogLevel.Info, "Master binding..." ) )
            {
                if( _spatialBindings.TryGetValue( target, out targetSpatialBinding ) )
                {
                    if( position == BindingPosition.Top && targetSpatialBinding.Top != null )
                    {
                        _logger.Trace( "{0} is already bound to {1} at position {2}.", targetSpatialBinding.Top.Window.Name, target.Name, position );
                        return false;
                    }
                    else if( position == BindingPosition.Left && targetSpatialBinding.Left != null )
                    {
                        _logger.Trace( "{0} is already bound to {1} at position {2}.", targetSpatialBinding.Left.Window.Name, target.Name, position );
                        return false;
                    }
                    else if( position == BindingPosition.Bottom && targetSpatialBinding.Bottom != null )
                    {
                        _logger.Trace( "{0} is already bound to {1} at position {2}.", targetSpatialBinding.Bottom.Window.Name, target.Name, position );
                        return false;
                    }
                    else if( position == BindingPosition.Right && targetSpatialBinding.Right != null )
                    {
                        _logger.Trace( "{0} is already bound to {1} at position {2}.", targetSpatialBinding.Right.Window.Name, target.Name, position );
                        return false;
                    }
                    else _logger.Trace( "{0} already exists in bindings but no window attached at position {1}.", target.Name, position );
                }
                else
                {
                    _logger.Trace( "Fresh new window" );
                }
            }

            using( _logger.OpenGroup( LogLevel.Info, "Slave binding..." ) )
            {
                if( _spatialBindings.TryGetValue( origin, out originSpatialBinding ) )
                {
                    if( position == BindingPosition.Top && originSpatialBinding.Bottom != null )
                    {
                        _logger.Trace( "{0} is already bound to {1} at position {2}.", originSpatialBinding.Bottom.Window.Name, target.Name, position );
                        return false;
                    }
                    else if( position == BindingPosition.Left && originSpatialBinding.Right != null )
                    {
                        _logger.Trace( "{0} is already bound to {1} at position {2}.", originSpatialBinding.Right.Window.Name, target.Name, position );
                        return false;
                    }
                    else if( position == BindingPosition.Bottom && originSpatialBinding.Top != null )
                    {
                        _logger.Trace( "{0} is already bound to {1} at position {2}.", originSpatialBinding.Top.Window.Name, target.Name, position );
                        return false;
                    }
                    else if( position == BindingPosition.Right && originSpatialBinding.Left != null )
                    {
                        _logger.Trace( "{0} is already bound to {1} at position {2}.", originSpatialBinding.Left.Window.Name, target.Name, position );
                        return false;
                    }
                    else _logger.Trace( "{0} already exists in bindings but no window attached at position {1}.", origin.Name, position );
                }
                else
                {
                    _logger.Trace( "Fresh new window" );
                    //spatialBinding = new SpatialBinding( slave );
                }
            }

            return true;
        }
Exemplo n.º 25
0
        public Rect GetClientArea( IWindowElement e )
        {
            WindowElementData d;
            _dic.TryGetValue( e, out d );
            if( d == null ) return Rect.Empty;

            return d.ToRect();
        }
Exemplo n.º 26
0
 public SpatialBinding( IWindowElement w )
 {
     Window = w;
 }
Exemplo n.º 27
0
        public virtual void Register( IWindowElement windowElement )
        {
            if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." );

            if( windowElement == null ) throw new ArgumentNullException( "windowElement" );
            if( _dic.ContainsKey( windowElement ) ) return;

            _dic.Add( windowElement, new WindowElementData
            {
                Window = windowElement,
                Height = windowElement.Height,
                Width = windowElement.Width,
                Left = windowElement.Left,
                Top = windowElement.Top
            } );

            windowElement.GotFocus += OnWindowGotFocusInternal;
            windowElement.Minimized += OnWindowMinimizedInternal;
            windowElement.Restored += OnWindowRestoredInternal;
            windowElement.LocationChanged += OnWindowLocationChangedInternal;
            windowElement.SizeChanged += OnWindowSizeChangedInternal;

            if( Registered != null )
                Registered( this, new WindowElementEventArgs( windowElement ) );
        }
Exemplo n.º 28
0
 void CleanUnbindButtonContainers( IWindowElement window )
 {
     UnbindButtonContainer container;
     if( _unbindButtonContainers.TryGetValue( window, out container ) )
     {
         if( container.TopButton == null
             && container.BottomButton == null
             && container.LeftButton == null
             && container.RightButton == null )
             _unbindButtonContainers.Remove( window );
     }
 }
Exemplo n.º 29
0
        public virtual void Unregister( IWindowElement windowElement )
        {
            if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." );

            if( windowElement == null )
                throw new InvalidOperationException( "The window element holder must hold a valid, non null reference to a window element." );

            WindowElementData data = null;
            if( _dic.TryGetValue( windowElement, out data ) )
            {
                data.Window.GotFocus -= OnWindowGotFocusInternal;
                data.Window.Minimized -= OnWindowMinimizedInternal;
                data.Window.Restored -= OnWindowRestoredInternal;
                data.Window.LocationChanged -= OnWindowLocationChangedInternal;
                data.Window.SizeChanged -= OnWindowSizeChangedInternal;
                _dic.Remove( windowElement );

                if( Unregistered != null )
                    Unregistered( this, new WindowElementEventArgs( windowElement ) );
            }
        }
Exemplo n.º 30
0
 void CreateButton( IWindowElement master, IWindowElement slave, BindingPosition position )
 {
     FillContainers( master, slave, position );
 }
        public void Start()
        {
            Debug.Assert( Dispatcher.CurrentDispatcher == Application.Current.Dispatcher, "This method should only be called by the Application Thread." );

            _vm = new TextualContextPreviewViewModel( TextualContextService );
            _window = new TextualContextPreviewWindow( _vm );
            _window.Width = 600;
            _window.Height = 300;
            _window.Show();

            _subscriber = new WindowManagerSubscriber( WindowManager, WindowBinder );
            _subscriber.OnBinderStarted = () =>
            {
                if( _textualContext != null & _me != null )
                    WindowBinder.Service.Bind( _textualContext, _me, BindingPosition.Top );
            };
            _subscriber.OnBinderStopped = () =>
            {
                if( _textualContext != null & _me != null )
                    WindowBinder.Service.Unbind( _textualContext, _me );
            };
            _subscriber.WindowRegistered = ( e ) =>
            {
                if( e.Window.Name == WindowName )
                {
                    _me = e.Window;
                    _textualContext = WindowManager.Service.GetByName( TextualContextArea.WindowName );
                }
                if( e.Window.Name == TextualContextArea.WindowName ) _textualContext = e.Window;

                _subscriber.OnBinderStarted();
            };
            _subscriber.WindowUnregistered = ( e ) =>
            {
                if( e.Window.Name == TextualContextArea.WindowName ) _subscriber.OnBinderStopped();
            };
            _subscriber.Subscribe( WindowName, _window );
        }
Exemplo n.º 32
0
        VMUnbindButton CreateVM( IWindowElement window, IWindowElement other, BindingPosition position )
        {
            Debug.Assert( Dispatcher.CurrentDispatcher == NoFocusManager.Default.ExternalDispatcher, "This method should only be called by the ExternalThread." );

            if( position == BindingPosition.None )
                return null;

            Action move = null;

            if( position == BindingPosition.Top )
            {
                move = () =>
                {
                    WindowManager.Service.Move( window, window.Top + 10, window.Left ).Broadcast();
                    WindowManager.Service.Move( other, other.Top - 10, other.Left ).Broadcast();
                };
            }
            else if( position == BindingPosition.Bottom )
            {
                move = () =>
                {
                    WindowManager.Service.Move( window, window.Top - 10, window.Left ).Broadcast();
                    WindowManager.Service.Move( other, other.Top + 10, other.Left ).Broadcast();
                };
            }
            else if( position == BindingPosition.Right )
            {
                move = () =>
                {
                    WindowManager.Service.Move( window, window.Top, window.Left - 10 ).Broadcast();
                    WindowManager.Service.Move( other, other.Top, other.Left + 10 ).Broadcast();
                };
            }
            else if( position == BindingPosition.Left )
            {
                move = () =>
                {
                    WindowManager.Service.Move( window, window.Top, window.Left + 10 ).Broadcast();
                    WindowManager.Service.Move( other, other.Top, other.Left - 10 ).Broadcast();
                };
            }

            return new VMUnbindButton( () =>
            {
                WindowBinder.Service.Unbind( window, other, false );
                move();
                EnableUnbindButtons();
            } );
        }