private void Hide() { try { System.Diagnostics.Debug.WriteLine("PopupInWindow.Hide(" + AssociatedObject.Name ?? "?" + ")"); if (PopupWindow == null || PopupWindow.Visibility == Visibility.Hidden) { return; } _skipHandler = true; var obj = AssociatedObject; var parent = obj.Parent; obj.MaxWidth = PopupWindow.ActualWidth; obj.MaxHeight = PopupWindow.ActualHeight; _insertIndex = parent.RemoveChild(obj); _parent.AddChild(obj, _insertIndex); } finally { PopupWindow.Hide(); _skipHandler = false; } }