Skip to content

Commit

Permalink
Merge pull request #1459 from robmikh/reordergridanimationfix
Browse files Browse the repository at this point in the history
Poke UIElement Z-Index when a container is being recycled in ReorderGridAnimation
  • Loading branch information
nmetulev authored Aug 31, 2017
2 parents 96b4b45 + 2214326 commit 2f745dc
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Microsoft.Toolkit.Uwp.UI.Animations/ReorderGridAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ private static void OnDurationChanged(DependencyObject d, DependencyPropertyChan

view.ContainerContentChanging -= OnContainerContentChanging;
view.ContainerContentChanging += OnContainerContentChanging;

view.ChoosingItemContainer -= OnChoosingItemContainer;
view.ChoosingItemContainer += OnChoosingItemContainer;
}
}

Expand All @@ -99,7 +102,7 @@ private static void OnContainerContentChanging(ListViewBase sender, ContainerCon
var elementVisual = ElementCompositionPreview.GetElementVisual(args.ItemContainer);
if (args.InRecycleQueue)
{
elementVisual.ImplicitAnimations = null;
PokeUIElementZIndex(args.ItemContainer);
}
else
{
Expand All @@ -108,6 +111,14 @@ private static void OnContainerContentChanging(ListViewBase sender, ContainerCon
}
}

private static void OnChoosingItemContainer(ListViewBase sender, ChoosingItemContainerEventArgs args)
{
if (args.ItemContainer != null)
{
PokeUIElementZIndex(args.ItemContainer);
}
}

private static CompositionAnimationGroup CreateOffsetAnimation(Compositor compositor, double duration)
{
Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation();
Expand All @@ -120,5 +131,12 @@ private static CompositionAnimationGroup CreateOffsetAnimation(Compositor compos

return animationGroup;
}

private static void PokeUIElementZIndex(UIElement element)
{
var oldZIndex = Canvas.GetZIndex(element);
Canvas.SetZIndex(element, oldZIndex + 1);
Canvas.SetZIndex(element, oldZIndex);
}
}
}

0 comments on commit 2f745dc

Please sign in to comment.