Example #1
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 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);
        }
        /// <summary>
        /// The get fade behaviour.
        /// </summary>
        /// <param name="frameworkElement"> The framework element. </param>
        /// <param name="beginTime"> The begin time. </param>
        /// <param name="duration"> The duration. </param>
        /// <returns> The <see cref="FadeBehavior"/>. </returns>
        private static FadeBehavior GetFadeBehavior(
            FrameworkElement frameworkElement,
            TimeSpan beginTime,
            TimeSpan duration)
        {
            BehaviorCollection behaviors = Interaction.GetBehaviors(frameworkElement);

            FadeBehavior fadeBehavior = behaviors
                                        .OfType <FadeBehavior>()
                                        .FirstOrDefault();

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

            fadeBehavior.BeginTime = beginTime;
            fadeBehavior.Duration  = duration;

            return(fadeBehavior);
        }
        /// <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;
            }
        }
        static void OnRegionChanged(DependencyObject obj, string oldValue, string newValue)
        {
            BehaviorCollection bCol = Interaction.GetBehaviors(obj);
            UIRegion           serv = bCol.OfType <UIRegion>().FirstOrDefault();

            if (serv != null)
            {
                serv.RegionName = newValue;
                return;
            }
            bCol.Add(new UIRegion()
            {
                RegionName = newValue
            });
        }
Example #6
0
        static void OnRegionChanged(DependencyObject obj, string oldValue, string newValue)
        {
            BehaviorCollection bCol        = Interaction.GetBehaviors(obj);
            UIRegion           oldUIRegion = bCol.OfType <UIRegion>().FirstOrDefault();

            if (oldUIRegion != null)
            {
                bCol.Remove(oldUIRegion);
            }
            if (!string.IsNullOrEmpty(newValue))
            {
                bCol.Add(new UIRegion()
                {
                    RegionName = newValue
                });
            }
        }
Example #7
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();
                };
            }
        }
Example #8
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();
                    }
                };
            }
        }