// 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); }