Exemplo n.º 1
0
        /// <summary>
        /// The initial collection animation.
        /// </summary>
        /// <param name="itemsControl"> The items control. </param>
        private static void InitCollectionAnimation(ItemsControl itemsControl)
        {
            Wizard wizard = itemsControl.FindVisualParent<Wizard>();
            WizardItem wizardItem = itemsControl.FindVisualParent<WizardItem>();

            if ((wizard != null) && (wizardItem != null))
            {
                WizardCollectionAnimation animation = (WizardCollectionAnimation)Enum.Parse(
                    typeof(WizardCollectionAnimation),
                    GetCollectionAnimation(itemsControl).ToString());

                BehaviorCollection behaviors = Interaction.GetBehaviors(itemsControl);
                AnimatingItemsControlBehavior behavior = behaviors.OfType<AnimatingItemsControlBehavior>().FirstOrDefault();

                if (behavior == null)
                {
                    behavior = new AnimatingItemsControlBehavior()
                    {
                        Duration = wizard.TransitionDuration.TimeSpan,
                        IsRandom = animation == WizardCollectionAnimation.Random
                    };
                    behaviors.Add(behavior);
                }

                wizardItem.Entering +=
                    (sender, e2) =>
                    {
                        behavior.AnimateIn();
                    };
                wizardItem.Leaving +=
                    (sender, e2) =>
                    {
                        behavior.AnimateOut();
                    };
            }
        }