public Task Run(Panel scene, HostControl backView, HostControl frontView, AnimationType animationType) { var tcs = new TaskCompletionSource <bool>(); if (IsRunning) { tcs.SetCanceled(); return(tcs.Task); } IsRunning = true; // // Creates a namescope that will be associated to the scene panel // to work around the Wpf bug when using Storyboard.SetTarget, use a namescope + Storyboard.SetTargetName instead // cf. http://connect.microsoft.com/VisualStudio/feedback/details/723701/storyboard-settarget-only-works-on-uielements-but-throws-no-exception // var sceneNameScope = NameScope.GetNameScope(scene); if (sceneNameScope == null) { sceneNameScope = new NameScope(); NameScope.SetNameScope(scene, sceneNameScope); } var transitionInfo = new TransitionInfo { Scene = scene, SceneNameScope = sceneNameScope, BackView = backView, FrontView = frontView, AnimationType = animationType }; // Storyboard completed handler var localTransitionInfo = transitionInfo; var storyboardCompletedAction = new Action(() => { // Clean OnRunTransitionCompleted(localTransitionInfo); IsRunning = false; tcs.SetResult(true); }); // Execute this code asynchronously in the dispatcher with the priority specified // so that we can be sure, it will be executed after the view was rendered Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { OnRunTransitionStarted(transitionInfo); var storyboard = CreateAnimation(transitionInfo); // if the storyboard is empty then trigger storyboard completion manually if (storyboard.Children.Count == 0) { storyboardCompletedAction(); } else { // If it is a 3D animation then hide views if (this is Transition3D) { EnsuresViewsAreHidden(backView, frontView); } else { EnsuresViewsAreVisible(backView, frontView); } storyboard.Completed += (sender, args) => storyboardCompletedAction(); storyboard.Begin(scene); } }), DispatcherPriority.Loaded); return(tcs.Task); }
protected virtual void OnRunTransitionCompleted(TransitionInfo transitionInfo) { }
protected abstract Storyboard CreateAnimation(TransitionInfo transitionInfo);
protected virtual void OnRunTransitionStarted(TransitionInfo transitionInfo) { }