Exemplo n.º 1
0
        public void JumpToPanoramaItemAnimated(int numPanelsToJump)
        {
            double t;

            switch (numPanelsToJump)
            {
            case 1:
                t = 550;
                break;

            case 2:
                t = 550;
                break;

            case 3:
                t = 650;
                break;

            case 4:
                t = 750;
                break;

            default:
                t = 750;
                break;
            }
            Panorama pan = this.mainPanorama; // ActualWidth 480

            double screenWidth = App.VM.ScreenWidth;

            FrameworkElement grid1 = VisualTreeHelper.GetChild(pan, 0) as FrameworkElement;
            FrameworkElement ptl   = VisualTreeHelper.GetChild(grid1, 1) as FrameworkElement; // W 1713
            FrameworkElement pl    = VisualTreeHelper.GetChild(grid1, 2) as FrameworkElement; // W 2160

            double translatePanTitle = -numPanelsToJump * 160;                                //

            int curIndex = pan.SelectedIndex;

            if (!(pl.RenderTransform is TranslateTransform) ||
                !(ptl.RenderTransform is TranslateTransform))
            {
                pl.RenderTransform  = new TranslateTransform();
                ptl.RenderTransform = new TranslateTransform();
            }

            this.LayoutRoot.Width = (1 + numPanelsToJump) * screenWidth;

            IEasingFunction easing = new CircleEase()
            {
                EasingMode = EasingMode.EaseInOut
            };

            // Animate the main panel
            Storyboard      sb = new Storyboard();
            DoubleAnimation a  = new DoubleAnimation()
            {
                From           = 0,
                To             = -numPanelsToJump * (pan.Items[curIndex] as PanoramaItem).ActualWidth,
                Duration       = new Duration(TimeSpan.FromMilliseconds(t)),
                EasingFunction = easing,
            };

            sb.Children.Add(a);
            Storyboard.SetTarget(a, pl.RenderTransform);
            Storyboard.SetTargetProperty(a, new PropertyPath(TranslateTransform.XProperty));

            // Animate title
            // scroll ~200
            DoubleAnimation aTitle = new DoubleAnimation()
            {
                From           = 0,
                To             = translatePanTitle,
                Duration       = new Duration(TimeSpan.FromMilliseconds(t)),
                EasingFunction = easing,
            };

            sb.Children.Add(aTitle);
            Storyboard.SetTarget(aTitle, ptl.RenderTransform);
            Storyboard.SetTargetProperty(aTitle, new PropertyPath(TranslateTransform.XProperty));

            sb.Completed += (obj, args) =>
            {
                this.LayoutRoot.Width = screenWidth;

                (pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Collapsed;
                pan.SetValue(Panorama.SelectedItemProperty, pan.Items[(curIndex + numPanelsToJump) % pan.Items.Count]);
                pan.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                (pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Visible;

                (pl.RenderTransform as TranslateTransform).X  = 0;
                (ptl.RenderTransform as TranslateTransform).X = 0;
                this.LayoutRoot.IsHitTestVisible = true;
            };

            this.LayoutRoot.IsHitTestVisible = false;

            sb.Begin();
        }
Exemplo n.º 2
0
        public void JumpBackAPanoramaItemAnimated()
        {
            Panorama         pan   = this.mainPanorama; // ActualWidth 480
            FrameworkElement grid1 = VisualTreeHelper.GetChild(pan, 0) as FrameworkElement;

            FrameworkElement ptl1   = VisualTreeHelper.GetChild(grid1, 1) as FrameworkElement;
            FrameworkElement sp2    = VisualTreeHelper.GetChild(ptl1, 0) as FrameworkElement;
            FrameworkElement cp2    = VisualTreeHelper.GetChild(sp2, 1) as FrameworkElement;
            FrameworkElement image1 = VisualTreeHelper.GetChild(cp2, 0) as FrameworkElement;
            FrameworkElement rect4  = VisualTreeHelper.GetChild(sp2, 2) as FrameworkElement;

            FrameworkElement pl    = VisualTreeHelper.GetChild(grid1, 2) as FrameworkElement;
            FrameworkElement sp3   = VisualTreeHelper.GetChild(pl, 0) as FrameworkElement;
            FrameworkElement rect5 = VisualTreeHelper.GetChild(sp3, 0) as FrameworkElement;
            FrameworkElement cp4   = VisualTreeHelper.GetChild(sp3, 1) as FrameworkElement;
            ItemsPresenter   ip1   = VisualTreeHelper.GetChild(cp4, 0) as ItemsPresenter;
            PanoramaPanel    pp    = VisualTreeHelper.GetChild(ip1, 0) as PanoramaPanel;
            PanoramaItem     pi1   = VisualTreeHelper.GetChild(pp, 0) as PanoramaItem;

            int numPanelsToJump = 4;

            double panItemWidth = pi1.ActualWidth;

            //double relfinalPanTitleTranslate = - numPanelsToJump * 160;
            //double titleJump = -(numPanelsToJump * panItemWidth);
            //double finalPanTitleTranslate = numPanelsToJump * panItemWidth + relfinalPanTitleTranslate;

            double relfinalPanTitleTranslate = -numPanelsToJump * 160;
            //double titleJump = -(image1.ActualWidth + 348);
            double titleJump = -(ptl1.ActualWidth - rect4.ActualWidth);
            double finalPanTitleTranslate = -titleJump + relfinalPanTitleTranslate;

            //rect4.Width = 0;

            int    lastInd          = pp.Children.Count - 1;
            int    currInd          = 0;
            int    numPanoramaItems = pp.Children.Count;
            double t = 550;

            IEasingFunction easing = new CubicEase()
            {
                EasingMode = EasingMode.EaseInOut,
            };

            UIElement pi = pp.Children[lastInd];

            pp.Children.Remove(pi);
            pp.Children.Insert(0, pi);
            // This jumps forward and messes up the title position
            pan.SetValue(Panorama.SelectedItemProperty, pp.Children[(currInd + 1) % numPanoramaItems] as PanoramaItem);

            ptl1.RenderTransform = new TranslateTransform();
            // Keep a reference to the RenderTransform on the StackPanel since this is used for the
            // inbuilt swipe navigation animation
            Transform spTransform = sp2.RenderTransform;

            // Set this offset since the home PanoramaItem is now the second in the list and the title
            // automatically jumps into the second PanoramaItem position
            sp2.RenderTransform = new TranslateTransform()
            {
                X = 0
            };
            pl.RenderTransform = new TranslateTransform()
            {
                X = 0
            };

            this.LayoutRoot.IsHitTestVisible = false;

            // Any smaller and it chops off the second instance of the title content
            this.LayoutRoot.Width = 3 * App.VM.ScreenWidth;
            // Need to set panorama to screen size and align to the left to remain onscreen
            pan.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            pan.Width = App.VM.ScreenWidth;

            Storyboard sb = new Storyboard();

            // Animate title using the StackPanel
            DoubleAnimation animTitle = new DoubleAnimation()
            {
                From           = 0,
                To             = finalPanTitleTranslate,
                Duration       = TimeSpan.FromMilliseconds(t),
                EasingFunction = easing,
            };

            sb.Children.Add(animTitle);
            Storyboard.SetTarget(animTitle, sp2.RenderTransform);
            Storyboard.SetTargetProperty(animTitle, new PropertyPath(TranslateTransform.XProperty));

            // Jump the entire panning layer back before animating the title so the second instance of ContentPresenter is shown
            // allowing the first instance to anmate in from the left
            DoubleAnimationUsingKeyFrames jumpTitleAnim = new DoubleAnimationUsingKeyFrames();

            jumpTitleAnim.KeyFrames.Add(new DiscreteDoubleKeyFrame()
            {
                KeyTime = TimeSpan.FromMilliseconds(0),
                Value   = titleJump,
            });
            sb.Children.Add(jumpTitleAnim);
            Storyboard.SetTarget(jumpTitleAnim, ptl1.RenderTransform);
            Storyboard.SetTargetProperty(jumpTitleAnim, new PropertyPath(TranslateTransform.XProperty));

            // Animate the main Panorama items
            DoubleAnimation animMain = new DoubleAnimation()
            {
                From           = 0,
                To             = panItemWidth,
                Duration       = TimeSpan.FromMilliseconds(t),
                EasingFunction = easing,
            };

            sb.Children.Add(animMain);
            Storyboard.SetTarget(animMain, pl.RenderTransform);
            Storyboard.SetTargetProperty(animMain, new PropertyPath(TranslateTransform.XProperty));

            sb.Begin();

            sb.Completed += (obj, args) =>
            {
                pan.Width             = App.VM.ScreenWidth;
                this.LayoutRoot.Width = App.VM.ScreenWidth;

                // Append PanoramaItem back to the end of the ItemsPresenter
                pp.Children.Remove(pi);
                pp.Children.Add(pi);

                (pl.RenderTransform as TranslateTransform).X   = 0;
                (ptl1.RenderTransform as TranslateTransform).X = 0;

                // Reset
                (pan.Items[(currInd + 1) & numPanoramaItems] as PanoramaItem).Visibility = Visibility.Collapsed;
                pan.SetValue(Panorama.SelectedItemProperty, pan.Items[lastInd]);
                pan.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                (pan.Items[(currInd + 1) & numPanoramaItems] as PanoramaItem).Visibility = Visibility.Visible;

                // Restore the StackPanel animation necessary for normal animation
                sp2.RenderTransform = spTransform;

                this.LayoutRoot.IsHitTestVisible = true;
            };
        }