public override void OnApplyTemplate() { if (this.IsTransitioning) { this.AbortTransition(); } if (this.CustomVisualStates != null && this.CustomVisualStates.Any()) { var presentationGroup = VisualStates.TryGetVisualStateGroup(this, PresentationGroup); if (presentationGroup != null) { foreach (var state in this.CustomVisualStates) { presentationGroup.States.Add(state); } } } base.OnApplyTemplate(); this.previousContentPresentationSite = this.GetTemplateChild(PreviousContentPresentationSitePartName) as ContentPresenter; this.currentContentPresentationSite = this.GetTemplateChild(CurrentContentPresentationSitePartName) as ContentPresenter; // hookup currenttransition Storyboard transition = this.GetStoryboard(this.Transition); this.CurrentTransition = transition; if (transition == null) { var invalidTransition = this.Transition; // revert to default this.Transition = DefaultTransitionState; throw new MahAppsException($"'{invalidTransition}' transition could not be found!"); } VisualStateManager.GoToState(this, HiddenState, false); }
private static void OnTransitionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var source = (TransitioningContentControl)d; var oldTransition = (TransitionType)e.OldValue; var newTransition = (TransitionType)e.NewValue; 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 (VisualStates.TryGetVisualStateGroup(source, PresentationGroup) == null) { // will delay check source.CurrentTransition = null; } else { // revert to old value source.SetValue(TransitionProperty, oldTransition); throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, "Temporary removed exception message", newTransition)); } } else { source.CurrentTransition = newStoryboard; } }