Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Completion handler for ThemeTransitions

Tags:

c#

uwp

uwp-xaml

The default UWP ListView style contains a few theme transitions in its ItemContainerTransitions TransitionCollection. Is there any way to know when the transition animation for a given theme transition is complete?

For example, I have a ListView and an accompanying button that adds an item to the list. I want to disable the button while an item is being added, since the animation gets cancelled if another gets queued up while in progress. I can easily disable the button based on the button Tapped event, but I need to know when I can re-enable it.

It seems like my options are:

1) Await a Task.Delay for the amount of time an AddDeleteThemeTransition takes. Seems pretty hacky.

2) Attempt to mimic the AddDeleteThemeTransition using Storyboard animations. I have this working, but seems like overkill. Composition could also be used, but is even further overkill than Storyboarded animations in my opinion.

As an aside, I haven't seen anyone implement their own Transition (i.e., inherit from the Transition class). It may not be relevant here, but is it even feasible?

like image 445
Tyler Southard Avatar asked Sep 20 '26 13:09

Tyler Southard


1 Answers

You're second idea of using Composition is actually the best, if you have a supported SDK. What you want to use is implicit animations defined on your elements or your ItemsPanel, as there is no proper way of being able to tell when the animation finishes.

ElementCompositionPreview.SetImplicitShowAnimation and ElementCompositionPreview.SetImplicitHideAnimation support you being able to set Implicit composition animations for adding / removing to the visual tree - and will avoid the stomping issue of one animation cancelling the other, and is more efficient than using Storyboards.

You also can't implement your own "Transition" as the class itself publicly exposes absolutely nothing, but now with Composition animations there's no need - composition is more powerful.

like image 108
Johnny Westlake Avatar answered Sep 22 '26 05:09

Johnny Westlake