private void SnapElement(IGadgetContainer container) { var gadgetContainerElement = container as UIElement; if (gadgetContainerElement == null) { return; } var elementRect = new Rect { X = GetLeft(gadgetContainerElement), Y = GetTop(gadgetContainerElement), Size = gadgetContainerElement.RenderSize }; if (_leftSnapRect.IntersectsWith(elementRect) || container.SnapRegion.Equals(SnapRegions.Top)) { SetLeft(gadgetContainerElement, 0); container.SnapRegion = SnapRegions.Left; } else if (_rightSnapRect.IntersectsWith(elementRect) || container.SnapRegion.Equals(SnapRegions.Right)) { SetLeft(gadgetContainerElement, ActualWidth - elementRect.Width); container.SnapRegion = SnapRegions.Right; } else if (_topSnapRect.IntersectsWith(elementRect) || container.SnapRegion.Equals(SnapRegions.Top)) { SetTop(gadgetContainerElement, 0); container.SnapRegion = SnapRegions.Top; } else if (_bottomSnapRect.IntersectsWith(elementRect) || container.SnapRegion.Equals(SnapRegions.Bottom)) { SetTop(gadgetContainerElement, ActualHeight - elementRect.Height); container.SnapRegion = SnapRegions.Bottom; } }