/// <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) { if (notificationWindows.Count > 0 && !notificationWindows.Any(i => i.ID == windowInfo.ID)) { return; } 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; notificationWindows.Remove(windowInfo); windowInfo.Window.Close(); if (notificationsBuffer != null && notificationsBuffer.Count > 0) { var BufferWindowInfo = notificationsBuffer.First(); Observable .Timer(BufferWindowInfo.DisplayDuration) .ObserveOnDispatcher() .Subscribe(x => OnTimerElapsed(BufferWindowInfo)); notificationWindows.Add(BufferWindowInfo); BufferWindowInfo.Window.Show(); notificationsBuffer.Remove(BufferWindowInfo); } }; fadeBehavior.FadeOutCompleted += eventHandler; } }
/// <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(); } }; } }