Example #1
0
 private void CheckState()
 {
     foreach (DataStateSwitchCase switchCase in this.States)
     {
         if (switchCase.IsValid(this.listener.Value))
         {
             FrameworkElement targetElement = GoToStateBase.FindTargetElement(this.AssociatedObject);
             if (targetElement != null)
             {
                 GoToStateBase.GoToState(targetElement, switchCase.State, true);
             }
             break;
         }
     }
 }
Example #2
0
        /// <summary>
        /// Hooks up to the necessary events on the VSM.
        /// </summary>
        protected override void OnAttached()
        {
            base.OnAttached();
#if SILVERLIGHT
            this.Dispatcher.BeginInvoke(delegate {
                this.vsgs = GoToStateBase.FindVSM(this.AssociatedObject);

                foreach (VisualStateGroup vsg in this.vsgs)
                {
                    if (this.Completed)
                    {
                        vsg.CurrentStateChanged += this.HandleStateChanged;
                    }
                    else
                    {
                        vsg.CurrentStateChanging += this.HandleStateChanged;
                    }
                }
            });
#else
            this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, (ThreadStart) delegate {
                this.vsgs = GoToStateBase.FindVSM(this.AssociatedObject);

                foreach (VisualStateGroup vsg in this.vsgs)
                {
                    if (this.Completed)
                    {
                        vsg.CurrentStateChanged += this.HandleStateChanged;
                    }
                    else
                    {
                        vsg.CurrentStateChanging += this.HandleStateChanged;
                    }
                }
            });
#endif
        }
Example #3
0
        /// <summary>
        /// Goes to the specified state on the targetted VSM.
        /// </summary>
        /// <param name="targetIndex">index of the state to be activated</param>
        /// <param name="useTransitions">True if transitions should be used.</param>
        protected void GoToState(int targetIndex, bool useTransitions)
        {
            FrameworkElement targetElement = this.TargetElement;

            if (targetElement == null)
            {
                return;
            }

            int index = 0;

            foreach (VisualStateGroup vsg in this.TargetVSM)
            {
                foreach (VisualState state in vsg.States)
                {
                    if (index == targetIndex)
                    {
                        GoToStateBase.GoToState(targetElement, state.Name, useTransitions);
                        break;
                    }
                    ++index;
                }
            }
        }