public override void OnApplyTemplate() { base.OnApplyTemplate(); ContentPresentationSite = GetTemplateChild(ContentPresentationSiteName) as ContentPresenter; StoryboardLeftIn = FindResource(ContentLeftInName) as Storyboard; if (StoryboardLeftIn != null) { if (StoryboardLeftIn.IsFrozen) { StoryboardLeftIn = StoryboardLeftIn.Clone(); StoryboardLeftIn.Completed += OnTransitionCompleted; } } StoryboardLeftOut = FindResource(ContentLeftOutName) as Storyboard; if (StoryboardLeftOut != null) { if (StoryboardLeftOut.IsFrozen) { StoryboardLeftOut = StoryboardLeftOut.Clone(); StoryboardLeftOut.Completed += OnTransitionCompleted; } } StoryboardRightIn = FindResource(ContentRightInName) as Storyboard; if (StoryboardRightIn != null) { if (StoryboardRightIn.IsFrozen) { StoryboardRightIn = StoryboardRightIn.Clone(); StoryboardRightIn.Completed += OnTransitionCompleted; } } StoryboardRightOut = FindResource(ContentRightOutName) as Storyboard; if (StoryboardRightOut != null) { if (StoryboardRightOut.IsFrozen) { StoryboardRightOut = StoryboardRightOut.Clone(); StoryboardRightOut.Completed += OnTransitionCompleted; } } if (ContentPresentationSite != null) { ContentPresentationSite.Content = Content; } //VisualStateManager.GoToState(this, NormalName, true); }
/// <summary> /// We have to use a clone to enable wiring up a method to the completed event /// otherwise the isfrozen state of the storyboard stays true and the method /// to the completed event can't be attached (exception thrown) /// </summary> /// <param name="storyboard"></param> private void WireUpStoryboard(Storyboard storyboard) { storyboard = storyboard.Clone(); storyboard.Begin(this); storyboard.Completed += MainWindowStoryboardCompleted; }