protected override void ClearContainerForItemOverride(DependencyObject element, object item) { FrameworkElement previousContainer = itemsSourceHelper.GetPreviousContainer(item); FrameworkElement nextContainer = itemsSourceHelper.GetNextContainer(item); if (previousContainer != null) { if (nextContainer == null) { previousContainer.Margin = ItemsControlHelper.GetLastItemMargin(this); } else { previousContainer.Margin = ItemsControlHelper.GetRegularItemMargin(this); } } itemsSourceHelper.UnregisterItemContainerPair(item); base.ClearContainerForItemOverride(element, item); }