Esempio n. 1
0
        private void ItemContainer_Loaded(object sender, RoutedEventArgs e)
        {
            var itemsPanel    = (ItemsStackPanel)ActivityList.ItemsPanelRoot;
            var itemContainer = (ListViewItem)sender;
            var itemIndex     = ActivityList.IndexFromContainer(itemContainer);

            var uc         = itemContainer.ContentTemplateRoot as FrameworkElement;
            var childPanel = uc.FindName("ActivityListItemPanel") as RelativePanel;

            // Don't animate if we're not in the visible viewport
            if (itemIndex >= itemsPanel.FirstVisibleIndex && itemIndex <= itemsPanel.LastVisibleIndex)
            {
                var itemVisual = ElementCompositionPreview.GetElementVisual(uc);

                float width  = (float)childPanel.RenderSize.Width;
                float height = (float)childPanel.RenderSize.Height;
                itemVisual.Size        = new Vector2(width, height);
                itemVisual.CenterPoint = new Vector3(width / 2, height / 2, 0f);
                itemVisual.Scale       = new Vector3(1, 1, 1); // new Vector3(0.25f, 0.25f, 0);
                itemVisual.Opacity     = 0f;
                itemVisual.Offset      = new Vector3(0, 100, 0);

                var relativeIndex = itemIndex - itemsPanel.FirstVisibleIndex;

                // Create KeyFrameAnimations
                KeyFrameAnimation offsetAnimation = Compositor.CreateScalarKeyFrameAnimation();
                offsetAnimation.InsertExpressionKeyFrame(1f, "0");
                offsetAnimation.Duration  = TimeSpan.FromMilliseconds(1250);
                offsetAnimation.DelayTime = TimeSpan.FromMilliseconds(relativeIndex * 100);

                Vector3KeyFrameAnimation scaleAnimation = Compositor.CreateVector3KeyFrameAnimation();
                scaleAnimation.InsertKeyFrame(0, new Vector3(1f, 1f, 0f));
                scaleAnimation.InsertKeyFrame(0.1f, new Vector3(0.05f, 0.05f, 0.05f));
                scaleAnimation.InsertKeyFrame(1f, new Vector3(1f, 1f, 0f));
                scaleAnimation.Duration  = TimeSpan.FromMilliseconds(1000);
                scaleAnimation.DelayTime = TimeSpan.FromMilliseconds(relativeIndex * 100);

                KeyFrameAnimation fadeAnimation = Compositor.CreateScalarKeyFrameAnimation();
                fadeAnimation.InsertExpressionKeyFrame(1f, "1");
                fadeAnimation.Duration  = TimeSpan.FromMilliseconds(500);
                fadeAnimation.DelayTime = TimeSpan.FromMilliseconds(relativeIndex * 100);

                // Start animations
                itemVisual.StartAnimation("Offset.Y", offsetAnimation);
                itemVisual.StartAnimation("Scale", scaleAnimation);
                itemVisual.StartAnimation("Opacity", fadeAnimation);
            }

            itemContainer.Loaded -= ItemContainer_Loaded;
        }