Ejemplo n.º 1
0
        private static void TryStartPivotHeaderAnimation(Pivot pivot, object NewItem, object OldItem)
        {
            if (NewItem == null)
            {
                return;
            }

            var NewIndex = -1;
            var OldIndex = -1;

            if (pivot.ContainerFromItem(OldItem) is PivotItem oldContainer)
            {
                OldIndex = pivot.IndexFromContainer(oldContainer);
            }

            if (pivot.ContainerFromItem(NewItem) is PivotItem newContainer)
            {
                NewIndex = pivot.IndexFromContainer(newContainer);
            }

            if (NewIndex >= 0)
            {
                var name = GetName(pivot);

                var Headers      = pivot.VisualTreeFindAll <PivotHeaderPanel>();
                var Header       = Headers.FirstOrDefault(c => c.Name == "Header");
                var StaticHeader = Headers.FirstOrDefault(c => c.Name == "StaticHeader");

                var newIndicator       = GetPivotHeaderIndicator(Header, name, NewIndex);
                var newStaticIndicator = GetPivotHeaderIndicator(StaticHeader, name, NewIndex);

                if (OldIndex >= 0)
                {
                    var oldIndicator       = GetPivotHeaderIndicator(Header, name, OldIndex);
                    var oldStaticIndicator = GetPivotHeaderIndicator(StaticHeader, name, OldIndex);

                    if (Header != null && newIndicator != null && oldIndicator != null)
                    {
                        TryStartPivotHeaderAnimation(Header, newIndicator, oldIndicator, GetIsScaleEnabled(pivot));
                    }
                    if (StaticHeader != null && newStaticIndicator != null && oldStaticIndicator != null)
                    {
                        TryStartPivotHeaderAnimation(StaticHeader, newStaticIndicator, oldStaticIndicator, GetIsScaleEnabled(pivot));
                    }
                }
                else
                {
                    if (newIndicator != null)
                    {
                        newIndicator.Visibility = Visibility.Visible;
                    }
                    if (newStaticIndicator != null)
                    {
                        newStaticIndicator.Visibility = Visibility.Visible;
                    }
                }
            }
        }