Example #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();
                            }
                        });
                    }
                    ;
                };
            };
        }
Example #2
0
        private static void OnIsPivotAnimatedChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            ItemsControl list = d as ItemsControl;

            list.Loaded += (RoutedEventHandler)((s2, e2) =>
            {
                Pivot pivot = list.Ancestors <Pivot>().Single <DependencyObject>() as Pivot;
                int pivotIndex = pivot.Items.IndexOf((object)list.Ancestors <PivotItem>().Single <DependencyObject>());
                bool selectionChanged = false;
                pivot.SelectionChanged += (SelectionChangedEventHandler)((s3, e3) => selectionChanged = true);
                pivot.ManipulationCompleted += (EventHandler <ManipulationCompletedEventArgs>)((s, e) =>
                {
                    if (!selectionChanged)
                    {
                        return;
                    }
                    selectionChanged = false;
                    if (pivotIndex != pivot.SelectedIndex)
                    {
                        return;
                    }
                    bool fromRight = e.TotalManipulation.Translation.X <= 0.0;
                    List <FrameworkElement> list1 = list.GetItemsInView().ToList <FrameworkElement>();
                    for (int index = 0; index < list1.Count; ++index)
                    {
                        FrameworkElement lbi = list1[index];
                        list.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            foreach (FrameworkElement element in lbi.Descendants().Where <DependencyObject>((Func <DependencyObject, bool>)(p => MetroInMotion.GetAnimationLevel(p) > -1)))
                            {
                                MetroInMotion.GetSlideAnimation(element, fromRight).Begin();
                            }
                        }));
                    }
                });
            });
        }
Example #3
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;

                    // locate the stack panel that hosts the items
                    VirtualizingStackPanel vsp = list.Descendants <VirtualizingStackPanel>().First() as VirtualizingStackPanel;

                    // iterate over each of the items in view
                    int firstVisibleItem = (int)vsp.VerticalOffset;
                    int visibleItemCount = (int)vsp.ViewportHeight;
                    for (int index = firstVisibleItem; index <= firstVisibleItem + visibleItemCount; index++)
                    {
                        // find all the item that have the AnimationLevel attached property set
                        var lbi = list.ItemContainerGenerator.ContainerFromIndex(index);
                        if (lbi == null)
                        {
                            continue;
                        }

                        vsp.Dispatcher.BeginInvoke(() =>
                        {
                            var animationTargets = lbi.Descendants().Where(p => ListAnimation.GetAnimationLevel(p) > -1);
                            foreach (FrameworkElement target in animationTargets)
                            {
                                // trigger the required animation
                                GetAnimation(target, fromRight).Begin();
                            }
                        });
                    }
                    ;
                };
            };
        }