Example #1
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedFrom(e);

            // Prepare backward transition connected animation
            if (e.NavigationMode == NavigationMode.Back)
            {
                // Pre-fall creator has different image loading order
                // unable to share same connected animation code without breaking the UI
                if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
                {
                    if (FlipView.SelectedIndex >= 0)
                    {
                        try
                        {
                            var container   = FlipView.ContainerFromIndex(FlipView.SelectedIndex) as FlipViewItem;
                            var mainPreview = container.ContentTemplateRoot as Grid;
                            var srollViewer = mainPreview.Children.First() as ScrollViewer;
                            var imageGrid   = srollViewer.Content as Grid;

                            // Prepare backward connected animation
                            var grid          = VisualTreeHelper.GetChild(FlipView, 0) as Grid;
                            var scrollingHost = grid.Children.FirstOrDefault(o => o is ScrollViewer) as UIElement;
                            ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("PreviewImage", imageGrid);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
        }
Example #2
0
        private void HandleConnectedAnimation()
        {
            // Pre-fall creator has different image loading order
            // unable to share same connected animation code without breaking the UI
            if (!ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
            {
                return;
            }


            try
            {
                var container = FlipView.ContainerFromIndex(FlipView.SelectedIndex) as FlipViewItem;


                // Do not play the animation if the target flipview item is not actually in the middle
                // even if the SelectedIndex is pointing it, there are chance that the UI component is still not in the correct position
                var   transform        = container.TransformToVisual(FlipView);
                Point absolutePosition = transform.TransformPoint(new Point(0, 0));
                if ((int)absolutePosition.X != 0)
                {
                    return;
                }


                var animation = ConnectedAnimationService.GetForCurrentView().GetAnimation("PreviewImage");
                if (animation != null)
                {
                    if (FlipView.SelectedIndex >= 0)
                    {
                        var mainPreview = container.ContentTemplateRoot as Grid;
                        var srollViewer = mainPreview.Children.First() as ScrollViewer;
                        var imageGrid   = srollViewer.Content as Grid;
                        // Prepare backward connected animation
                        if (!animation.TryStart(imageGrid))
                        {
                            readyForConnectedAnimation = false;
                        }
                        else
                        {
                            readyForConnectedAnimation = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
 public void InitAnimation(InitOption Option)
 {
     if (compositor != null)
     {
         if (Option == InitOption.AroundImage)
         {
             for (int i = Flip.SelectedIndex > 2 ? Flip.SelectedIndex - 2 : 0; i < Flip.SelectedIndex + 2 && i < Flip.Items.Count; i++)
             {
                 if (Flip.ContainerFromIndex(i) is UIElement Element)
                 {
                     var Visual = ElementCompositionPreview.GetElementVisual(Element);
                     CenterPointAnimation.SetReferenceParameter("visual", Visual);
                     Visual.StartAnimation("CenterPoint", CenterPointAnimation);
                     Visual.StopAnimation("Scale.X");
                     ScaleAnimation.SetReferenceParameter("visual", Visual);
                     Visual.StartAnimation("Scale.X", ScaleAnimation);
                     Visual.StartAnimation("Scale.Y", ScaleAnimation);
                 }
             }
         }
         else
         {
             foreach (var Visual in from Item in Flip.Items
                      let Element = Flip.ContainerFromItem(Item) as UIElement
                                    where Element != null
                                    select ElementCompositionPreview.GetElementVisual(Element))
             {
                 CenterPointAnimation.SetReferenceParameter("visual", Visual);
                 Visual.StartAnimation("CenterPoint", CenterPointAnimation);
                 Visual.StopAnimation("Scale.X");
                 ScaleAnimation.SetReferenceParameter("visual", Visual);
                 Visual.StartAnimation("Scale.X", ScaleAnimation);
                 Visual.StartAnimation("Scale.Y", ScaleAnimation);
             }
         }
     }
 }