/// <summary>
        /// The get slide behaviour.
        /// </summary>
        /// <param name="frameworkElement"> The framework element. </param>
        /// <param name="beginTime"> The begin time. </param>
        /// <param name="duration"> The duration. </param>
        /// <param name="offset"> The offset. </param>
        /// <returns> The <see cref="SlideBehavior"/>. </returns>
        private static SlideBehavior GetSlideBehavior(
            FrameworkElement frameworkElement,
            TimeSpan beginTime,
            TimeSpan duration,
            double offset)
        {
            BehaviorCollection behaviors = Interaction.GetBehaviors(frameworkElement);

            SlideBehavior slideBehavior = behaviors
                                          .OfType <SlideBehavior>()
                                          .FirstOrDefault();

            if (slideBehavior == null)
            {
                slideBehavior =
                    new SlideBehavior()
                {
                    IsAnimatingOnIsVisibleChanged = false,
                    IsAnimatingOnLoaded           = false
                };
                behaviors.Add(slideBehavior);
            }

            slideBehavior.BeginTime = beginTime;
            slideBehavior.Duration  = duration;
            slideBehavior.Offset    = offset;

            return(slideBehavior);
        }
Exemple #2
0
        /// <summary>
        /// Called when the timer has elapsed. Removes any stale notifications.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param>
        private static void OnTimerElapsed(WindowInfo windowInfo)
        {
            DateTime now = DateTime.Now;

            if (windowInfo.Window.IsMouseOver)
            {
                Observable
                .Timer(windowInfo.DisplayDuration)
                .ObserveOnDispatcher()
                .Subscribe(x => OnTimerElapsed(windowInfo));
            }
            else
            {
                BehaviorCollection behaviors     = Interaction.GetBehaviors(windowInfo.Window);
                FadeBehavior       fadeBehavior  = behaviors.OfType <FadeBehavior>().First();
                SlideBehavior      slideBehavior = behaviors.OfType <SlideBehavior>().First();

                fadeBehavior.FadeOut();
                slideBehavior.SlideOut();

                EventHandler eventHandler = null;
                eventHandler = (sender2, e2) =>
                {
                    fadeBehavior.FadeOutCompleted -= eventHandler;
                    windows.Remove(windowInfo);
                    windowInfo.Window.Close();
                };
                fadeBehavior.FadeOutCompleted += eventHandler;
            }
        }
        /// <summary>
        /// The animate out.
        /// </summary>
        public void AnimateOut()
        {
            if (this.AssociatedObject.Items.Count == 0)
            {
                this.OnAnimateOutCompleted(this, EventArgs.Empty);
            }
            else
            {
                if (this.AssociatedObject.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
                {
                    TimeSpan beginTime = this.Interval;

                    FrameworkElement selectedItem = GetSelectedItem(this.AssociatedObject);

                    foreach (object item in this.AssociatedObject.Items.Cast <object>().Reverse())
                    {
                        FrameworkElement frameworkElement = (FrameworkElement)this.AssociatedObject.ItemContainerGenerator.ContainerFromItem(item);
                        if (frameworkElement != null)
                        {
                            bool isFirst = this.AssociatedObject.Items.IndexOf(item) == 0;

                            if (this.IsRandom)
                            {
                                if (isFirst)
                                {
                                    beginTime = new TimeSpan(0, 0, 0, 0, 7 * 35);
                                }
                                else
                                {
                                    beginTime = new TimeSpan(0, 0, 0, 0, this.random.Next(0, 7) * 35);
                                }
                            }
                            else
                            {
                                beginTime = beginTime + this.Interval;
                            }

                            FadeBehavior fadeBehavior = GetFadeBehavior(
                                frameworkElement,
                                beginTime,
                                this.Duration);
                            SlideBehavior slideBehavior = GetSlideBehavior(
                                frameworkElement,
                                beginTime,
                                this.Duration,
                                this.Offset);

                            if (isFirst)
                            {
                                if (item != selectedItem)
                                {
                                    EventHandler eventHandler = null;
                                    eventHandler = (sender, e) =>
                                    {
                                        slideBehavior.SlideOutCompleted -= eventHandler;
                                        this.OnAnimateOutCompleted(this, EventArgs.Empty);
                                    };
                                    slideBehavior.SlideOutCompleted += eventHandler;
                                }
                                else
                                {
                                    EventHandler eventHandler = null;
                                    eventHandler = (sender, e) =>
                                    {
                                        fadeBehavior.FadeOutCompleted -= eventHandler;
                                        this.OnAnimateOutCompleted(this, EventArgs.Empty);
                                    };
                                    fadeBehavior.FadeOutCompleted += eventHandler;
                                }
                            }

                            fadeBehavior.FadeOut();

                            // Do not animate out the selected item.
                            if (item != selectedItem)
                            {
                                slideBehavior.SlideOut();
                            }
                        }
                    }
                }
                else
                {
                    EventHandler eventHandler = null;
                    eventHandler =
                        (sender, e) =>
                    {
                        this.AssociatedObject.ItemContainerGenerator.StatusChanged -= eventHandler;
                        this.AnimateIn();
                    };
                    this.AssociatedObject.ItemContainerGenerator.StatusChanged += eventHandler;
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// The initial animation.
        /// </summary>
        /// <param name="frameworkElement"> The framework element. </param>
        private static void InitAnimation(FrameworkElement frameworkElement)
        {
            Wizard     wizard     = frameworkElement.FindVisualParent <Wizard>();
            WizardItem wizardItem = frameworkElement.FindVisualParent <WizardItem>();

            if ((wizard != null) && (wizardItem != null))
            {
                WizardAnimation animation = (WizardAnimation)Enum.Parse(
                    typeof(WizardAnimation),
                    GetAnimation(frameworkElement).ToString());

                BehaviorCollection behaviors = Interaction.GetBehaviors(frameworkElement);

                FadeBehavior fadeBehavior = null;
                if ((animation == WizardAnimation.Fade) || (animation == WizardAnimation.FadeAndSlide))
                {
                    fadeBehavior = behaviors.OfType <FadeBehavior>().FirstOrDefault();
                    if (fadeBehavior == null)
                    {
                        fadeBehavior = new FadeBehavior()
                        {
                            Duration = wizard.TransitionDuration.TimeSpan,
                        };
                        behaviors.Add(fadeBehavior);
                    }
                }

                SlideBehavior slideBehavior = null;
                if ((animation == WizardAnimation.Slide) || (animation == WizardAnimation.FadeAndSlide))
                {
                    slideBehavior = behaviors.OfType <SlideBehavior>().FirstOrDefault();
                    if (slideBehavior == null)
                    {
                        slideBehavior = new SlideBehavior()
                        {
                            Duration = wizard.TransitionDuration.TimeSpan,
                        };
                        behaviors.Add(slideBehavior);
                    }
                }

                wizardItem.Entering +=
                    (sender, e2) =>
                {
                    if (fadeBehavior != null)
                    {
                        fadeBehavior.FadeIn();
                    }

                    if (slideBehavior != null)
                    {
                        slideBehavior.SlideIn();
                    }
                };
                wizardItem.Leaving +=
                    (sender, e2) =>
                {
                    if (fadeBehavior != null)
                    {
                        fadeBehavior.FadeOut();
                    }

                    if (slideBehavior != null)
                    {
                        slideBehavior.SlideOut();
                    }
                };
            }
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.Behavior = ((Framework.UI.Controls.AnimatingItemsControlBehavior)(target));
                return;

            case 2:

            #line 52 "..\..\..\Views\AnimationView.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.OnAnimateIn);

            #line default
            #line hidden
                return;

            case 3:

            #line 55 "..\..\..\Views\AnimationView.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.OnAnimateOut);

            #line default
            #line hidden
                return;

            case 4:
                this.Slider = ((System.Windows.Controls.Slider)(target));
                return;

            case 5:
                this.AnimatingItem = ((System.Windows.Controls.Border)(target));
                return;

            case 6:
                this.FadeBehavior = ((Framework.UI.Controls.FadeBehavior)(target));

            #line 100 "..\..\..\Views\AnimationView.xaml"
                this.FadeBehavior.FadeOutCompleted += new System.EventHandler(this.OnFadeOutCompleted);

            #line default
            #line hidden
                return;

            case 7:
                this.SlideBehavior = ((Framework.UI.Controls.SlideBehavior)(target));
                return;

            case 8:

            #line 105 "..\..\..\Views\AnimationView.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.OnShow);

            #line default
            #line hidden
                return;

            case 9:

            #line 108 "..\..\..\Views\AnimationView.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.OnCollapse);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.Behavior = ((Framework.UI.Controls.AnimatingItemsControlBehavior)(target));
     return;
     case 2:
     
     #line 52 "..\..\..\Views\AnimationView.xaml"
     ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.OnAnimateIn);
     
     #line default
     #line hidden
     return;
     case 3:
     
     #line 55 "..\..\..\Views\AnimationView.xaml"
     ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.OnAnimateOut);
     
     #line default
     #line hidden
     return;
     case 4:
     this.Slider = ((System.Windows.Controls.Slider)(target));
     return;
     case 5:
     this.AnimatingItem = ((System.Windows.Controls.Border)(target));
     return;
     case 6:
     this.FadeBehavior = ((Framework.UI.Controls.FadeBehavior)(target));
     
     #line 100 "..\..\..\Views\AnimationView.xaml"
     this.FadeBehavior.FadeOutCompleted += new System.EventHandler(this.OnFadeOutCompleted);
     
     #line default
     #line hidden
     return;
     case 7:
     this.SlideBehavior = ((Framework.UI.Controls.SlideBehavior)(target));
     return;
     case 8:
     
     #line 105 "..\..\..\Views\AnimationView.xaml"
     ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.OnShow);
     
     #line default
     #line hidden
     return;
     case 9:
     
     #line 108 "..\..\..\Views\AnimationView.xaml"
     ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.OnCollapse);
     
     #line default
     #line hidden
     return;
     }
     this._contentLoaded = true;
 }