private void ElementOnPropertyChanged(object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case "Renderer": var element = Element; if (element == null) { return; } //We want our handlers after the renderer, so re-register UnregisterHandlers(element); RegisterHandlers(element); _handler?.Attach(this); break; default: if (!ShouldTransition(e.PropertyName)) { return; } IsAnimating = false; //won't end the animation right away if batched break; } }
public Task Animate(Action action) { if (_handler == null) { action(); return(Task.FromResult(0)); } var tcs = new TaskCompletionSource <bool>(); _handler.Completed += Handler; _handler.Attach(this); action(); return(tcs.Task); void Handler(object _, EventArgs __) { _handler.Completed -= Handler; tcs.TrySetResult(true); } }