protected void RaiseCurrentStateChanged(VisualStateGroup stateGroup, VisualState oldState, VisualState newState, Control control)
        {
            if (stateGroup == null)
            {
                throw new ArgumentNullException("stateGroup");
            }

            if (newState == null)
            {
                throw new ArgumentNullException("newState");
            }

            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            FrameworkElement root = VisualStateManager.GetTemplateRoot(control);

            if (root == null)
            {
                return; // Ignore if a ControlTemplate hasn't been applied
            }

            stateGroup.RaiseCurrentStateChanged(root, oldState, newState, control);
        }
Ejemplo n.º 2
0
 /// <summary>Raises the <see cref="E:System.Windows.VisualStateGroup.CurrentStateChanging" /> event on the specified <see cref="T:System.Windows.VisualStateGroup" /> object.</summary>
 /// <param name="stateGroup">The object that the <see cref="E:System.Windows.VisualStateGroup.CurrentStateChanging" /> event occurred on.</param>
 /// <param name="oldState">The state that the control is transitioning from.</param>
 /// <param name="newState">The state that the control is transitioning to.</param>
 /// <param name="control">The control that is transitioning states.</param>
 /// <param name="stateGroupsRoot">The root element that contains the <see cref="T:System.Windows.VisualStateManager" />.</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///         <paramref name="stateGroupsRoot" /> is <see langword="null" />.-or-
 ///         <paramref name="newState" /> is <see langword="null" />.</exception>
 // Token: 0x06000CFD RID: 3325 RVA: 0x000303DA File Offset: 0x0002E5DA
 protected void RaiseCurrentStateChanged(VisualStateGroup stateGroup, VisualState oldState, VisualState newState, FrameworkElement control, FrameworkElement stateGroupsRoot)
 {
     if (stateGroup == null)
     {
         throw new ArgumentNullException("stateGroup");
     }
     if (newState == null)
     {
         throw new ArgumentNullException("newState");
     }
     if (stateGroupsRoot == null)
     {
         return;
     }
     stateGroup.RaiseCurrentStateChanged(stateGroupsRoot, oldState, newState, control);
 }
Ejemplo n.º 3
0
        private static bool GoToStateInternal(FrameworkElement control, FrameworkElement stateGroupsRoot, VisualStateGroup group, VisualState state, bool useTransitions)
        {
            if (stateGroupsRoot == null)
            {
                throw new ArgumentNullException("stateGroupsRoot");
            }

            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            if (group == null)
            {
                throw new InvalidOperationException();
            }

            VisualState lastState = group.CurrentState;

            if (lastState == state)
            {
                return(true);
            }

            // Get the transition Storyboard. Even if there are no transitions specified, there might
            // be properties that we're rolling back to their default values.
            VisualTransition transition = useTransitions ? VisualStateManager.GetTransition(stateGroupsRoot, group, lastState, state) : null;

            // Generate dynamicTransition Storyboard
            Storyboard dynamicTransition = GenerateDynamicTransitionAnimations(stateGroupsRoot, group, state, transition);

            // If the transition is null, then we want to instantly snap. The dynamicTransition will
            // consist of everything that is being moved back to the default state.
            // If the transition.Duration and explicit storyboard duration is zero, then we want both the dynamic
            // and state Storyboards to happen in the same tick, so we start them at the same time.
            if (transition == null || (transition.GeneratedDuration == DurationZero &&
                                       (transition.Storyboard == null || transition.Storyboard.Duration == DurationZero)))
            {
                // Start new state Storyboard and stop any previously running Storyboards
                if (transition != null && transition.Storyboard != null)
                {
                    group.StartNewThenStopOld(stateGroupsRoot, transition.Storyboard, state.Storyboard);
                }
                else
                {
                    group.StartNewThenStopOld(stateGroupsRoot, state.Storyboard);
                }

                // Fire both CurrentStateChanging and CurrentStateChanged events
                group.RaiseCurrentStateChanging(stateGroupsRoot, lastState, state, control);
                group.RaiseCurrentStateChanged(stateGroupsRoot, lastState, state, control);
            }
            else
            {
                // In this case, we have an interstitial storyboard of duration > 0 and/or
                // explicit storyboard of duration >0 , so we need
                // to run them first, and then we'll run the state storyboard.
                // we have to wait for both storyboards to complete before
                // starting the steady state animations.
                transition.DynamicStoryboardCompleted = false;

                // Hook up generated Storyboard's Completed event handler
                dynamicTransition.Completed += delegate(object sender, EventArgs e)
                {
                    if (transition.Storyboard == null || transition.ExplicitStoryboardCompleted)
                    {
                        if (ShouldRunStateStoryboard(control, stateGroupsRoot, state, group))
                        {
                            group.StartNewThenStopOld(stateGroupsRoot, state.Storyboard);
                        }

                        group.RaiseCurrentStateChanged(stateGroupsRoot, lastState, state, control);
                    }

                    transition.DynamicStoryboardCompleted = true;
                };

                if (transition.Storyboard != null && transition.ExplicitStoryboardCompleted == true)
                {
                    EventHandler transitionCompleted = null;
                    transitionCompleted = new EventHandler(delegate(object sender, EventArgs e)
                    {
                        if (transition.DynamicStoryboardCompleted)
                        {
                            if (ShouldRunStateStoryboard(control, stateGroupsRoot, state, group))
                            {
                                group.StartNewThenStopOld(stateGroupsRoot, state.Storyboard);
                            }

                            group.RaiseCurrentStateChanged(stateGroupsRoot, lastState, state, control);
                        }

                        transition.Storyboard.Completed       -= transitionCompleted;
                        transition.ExplicitStoryboardCompleted = true;
                    });

                    // hook up explicit storyboard's Completed event handler
                    transition.ExplicitStoryboardCompleted = false;
                    transition.Storyboard.Completed       += transitionCompleted;
                }

                // Start transition and dynamicTransition Storyboards
                // Stop any previously running Storyboards
                group.StartNewThenStopOld(stateGroupsRoot, transition.Storyboard, dynamicTransition);

                group.RaiseCurrentStateChanging(stateGroupsRoot, lastState, state, control);
            }

            group.CurrentState = state;

            return(true);
        }
Ejemplo n.º 4
0
        // Token: 0x06000CFA RID: 3322 RVA: 0x000300A4 File Offset: 0x0002E2A4
        private static bool GoToStateInternal(FrameworkElement control, FrameworkElement stateGroupsRoot, VisualStateGroup group, VisualState state, bool useTransitions)
        {
            if (stateGroupsRoot == null)
            {
                throw new ArgumentNullException("stateGroupsRoot");
            }
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }
            if (group == null)
            {
                throw new InvalidOperationException();
            }
            VisualState lastState = group.CurrentState;

            if (lastState == state)
            {
                return(true);
            }
            VisualTransition transition = useTransitions ? VisualStateManager.GetTransition(stateGroupsRoot, group, lastState, state) : null;
            Storyboard       storyboard = VisualStateManager.GenerateDynamicTransitionAnimations(stateGroupsRoot, group, state, transition);

            if (transition == null || (transition.GeneratedDuration == VisualStateManager.DurationZero && (transition.Storyboard == null || transition.Storyboard.Duration == VisualStateManager.DurationZero)))
            {
                if (transition != null && transition.Storyboard != null)
                {
                    group.StartNewThenStopOld(stateGroupsRoot, new Storyboard[]
                    {
                        transition.Storyboard,
                        state.Storyboard
                    });
                }
                else
                {
                    group.StartNewThenStopOld(stateGroupsRoot, new Storyboard[]
                    {
                        state.Storyboard
                    });
                }
                group.RaiseCurrentStateChanging(stateGroupsRoot, lastState, state, control);
                group.RaiseCurrentStateChanged(stateGroupsRoot, lastState, state, control);
            }
            else
            {
                transition.DynamicStoryboardCompleted = false;
                storyboard.Completed += delegate(object sender, EventArgs e)
                {
                    if (transition.Storyboard == null || transition.ExplicitStoryboardCompleted)
                    {
                        if (VisualStateManager.ShouldRunStateStoryboard(control, stateGroupsRoot, state, group))
                        {
                            group.StartNewThenStopOld(stateGroupsRoot, new Storyboard[]
                            {
                                state.Storyboard
                            });
                        }
                        group.RaiseCurrentStateChanged(stateGroupsRoot, lastState, state, control);
                    }
                    transition.DynamicStoryboardCompleted = true;
                };
                if (transition.Storyboard != null && transition.ExplicitStoryboardCompleted)
                {
                    EventHandler transitionCompleted = null;
                    transitionCompleted = delegate(object sender, EventArgs e)
                    {
                        if (transition.DynamicStoryboardCompleted)
                        {
                            if (VisualStateManager.ShouldRunStateStoryboard(control, stateGroupsRoot, state, group))
                            {
                                group.StartNewThenStopOld(stateGroupsRoot, new Storyboard[]
                                {
                                    state.Storyboard
                                });
                            }
                            group.RaiseCurrentStateChanged(stateGroupsRoot, lastState, state, control);
                        }
                        transition.Storyboard.Completed       -= transitionCompleted;
                        transition.ExplicitStoryboardCompleted = true;
                    };
                    transition.ExplicitStoryboardCompleted = false;
                    transition.Storyboard.Completed       += transitionCompleted;
                }
                group.StartNewThenStopOld(stateGroupsRoot, new Storyboard[]
                {
                    transition.Storyboard,
                    storyboard
                });
                group.RaiseCurrentStateChanging(stateGroupsRoot, lastState, state, control);
            }
            group.CurrentState = state;
            return(true);
        }