Exemple #1
0
        private static void OnIsPivotAnimatedChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            ItemsControl list = d as ItemsControl;

            list.Loaded += (s2, e2) =>
            {
                // locate the pivot control that this list is within
                Pivot pivot = list.Ancestors <Pivot>().Single() as Pivot;

                // and its index within the pivot
                int pivotIndex = pivot.Items.IndexOf(list.Ancestors <PivotItem>().Single());

                bool selectionChanged = false;

                pivot.SelectionChanged += (s3, e3) =>
                {
                    selectionChanged = true;
                };

                // handle manipulation events which occur when the user
                // moves between pivot items
                pivot.ManipulationCompleted += (s, e) =>
                {
                    if (!selectionChanged)
                    {
                        return;
                    }

                    selectionChanged = false;

                    if (pivotIndex != pivot.SelectedIndex)
                    {
                        return;
                    }

                    // determine which direction this tab will be scrolling in from
                    bool fromRight = e.TotalManipulation.Translation.X <= 0;


                    // iterate over each of the items in view
                    var items = list.GetItemsInView().ToList();
                    for (int index = 0; index < items.Count; index++)
                    {
                        var lbi = items[index];

                        list.Dispatcher.BeginInvoke(() =>
                        {
                            var animationTargets = lbi.Descendants()
                                                   .Where(p => MetroInMotion.GetAnimationLevel(p) > -1);
                            foreach (FrameworkElement target in animationTargets)
                            {
                                // trigger the required animation
                                GetSlideAnimation(target, fromRight).Begin();
                            }
                        });
                    }
                    ;
                };
            };
        }
Exemple #2
0
        /// <summary>
        /// Creates a TranslateTransform and associates it with the given element, returning
        /// a Storyboard which will animate the TranslateTransform with a SineEase function
        /// </summary>
        private static Storyboard GetSlideAnimation(FrameworkElement element, bool fromRight)
        {
            double from = fromRight ? 80 : -80;

            Storyboard sb;
            double     delay = (MetroInMotion.GetAnimationLevel(element)) * 0.1 + 0.1;

            TranslateTransform trans = new TranslateTransform()
            {
                X = from
            };

            element.RenderTransform = trans;

            sb           = new Storyboard();
            sb.BeginTime = TimeSpan.FromSeconds(delay);
            sb.Children.Add(CreateAnimation(from, 0, 0.8, "X", trans));
            return(sb);
        }