/// <summary> /// Attempts to find a storyboard that matches the newTransition name. /// </summary> /// <param name="newTransition">The new transition.</param> /// <returns>A storyboard or null, if no storyboard was found.</returns> private Storyboard GetStoryboard(string newTransition) { VisualStateGroup presentationGroup = VisualStateHelper.TryGetVisualStateGroup(this, PresentationGroup); Storyboard newStoryboard = null; if (presentationGroup != null) { newStoryboard = presentationGroup.States .OfType <VisualState>() .Where(state => state.Name == newTransition) .Select(state => state.Storyboard) .FirstOrDefault(); } return(newStoryboard); }
/// <summary> /// TransitionProperty property changed handler. /// </summary> /// <param name="d">TransitioningContentControl that changed its Transition.</param> /// <param name="e">Event arguments.</param> private static void OnTransitionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TransitioningContentControl source = (TransitioningContentControl)d; string oldTransition = e.OldValue as string; string newTransition = e.NewValue as string; if (source.IsTransitioning) { source.AbortTransition(); } // find new transition Storyboard newStoryboard = source.GetStoryboard(newTransition); // unable to find the transition. if (newStoryboard == null) { // could be during initialization of xaml that presentationgroups was not yet defined if (VisualStateHelper.TryGetVisualStateGroup(source, PresentationGroup) == null) { // will delay check source.CurrentTransition = null; } else { // revert to old value source.SetValue(TransitionProperty, oldTransition); throw new ArgumentException( "TransitioningContentControl_TransitionNotFound"); } } else { source.CurrentTransition = newStoryboard; } }