public Renderer(CompositionTargetSecondsTimerSystem timerSystem, Behavior <DrawableDelegate> drawable, Size size, Animate animation, Cell <bool> isStarted) { this.drawable = drawable; this.size = size; Transaction.RunVoid(() => isStarted.Values().Filter(s => s).ListenOnce(_ => timerSystem.AddAnimation(animation))); }
public Animate(AnimationDelegate animation, Size size) { TaskCompletionSource <Renderer> tcs = new TaskCompletionSource <Renderer>(); this.renderer = tcs.Task; void CreateTimerSystem(object sender, EventArgs args) { CompositionTargetSecondsTimerSystem timerSystem = CompositionTargetSecondsTimerSystem.Create(((RenderingEventArgs)args).RenderingTime.TotalSeconds, e => this.Dispatcher.Invoke(() => throw e)); Point extents = new Point(size.Width / 2, size.Height / 2); tcs.SetResult(new Renderer(timerSystem, Transaction.Run(() => Shapes.Translate(animation(timerSystem, extents), Behavior.Constant(extents))), size, this, this.isStarted)); CompositionTarget.Rendering -= CreateTimerSystem; } CompositionTarget.Rendering += CreateTimerSystem; }