private void WindowStoppedMoving(UIFrame MovedFrame) { // Put it back in this view RemoveSubview(MovedFrame); UIFrame LastWindowAbove = null; foreach (UIFrame Window in ContentView.SubviewsOfType <UIFrame>()) { // Check if dropped above another window int TopOfWindow = ContentView.ClientBounds.Top + Window.Bounds.Y + Window.Bounds.Height / 2; if (MovedFrame.Bounds.Y < TopOfWindow) { LastWindowAbove = Window; break; } } // Add it to the content view again if (LastWindowAbove != null) { ContentView.AddSubviewBefore(MovedFrame, LastWindowAbove); } else { ContentView.AddSubview(MovedFrame); } }