Theme Transitions #15538
DarthMazut
started this conversation in
Show and tell
Theme Transitions
#15538
Replies: 1 comment
-
Avalonia does have animations that can play when a control is created, however as a result it can behave kind of weird when using it with a virtualised panel. As the control will be created and destroyed as needed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I recently was working with WinUI3. I noticted that there is something called
Theme Transitions
. Basically it works like this:This is example straight from
WinUI 3 Gallery
. So as you can see it's enough to just addEnteranceThemeTransition
intoChildrenTranstitions
and voila! We're having this beautiful, smooth animations whenever items are added, removed etc...I started wondering whether there is something similar in Avalonia, but unfortunatelly I did not find anything close. Sure, we have
Transition
for quite a lot of types, but to actually animate item, you'd need e.g. put in on Canvas and animate its position like e.g.ToggleSwitch
is doing. So for me it was quite a lot of work anyway. My expectation is to place item normally, e.g. within grid or stackpanel and just declare that whether this item's child changes its position it should be smooth.So to avoid placing item on the Canvas, I came up with this idea to make something similar like WinUI 3 theme transitions.
So my overnight work looks like this:
On the left side, there is an ItemsControl - it's bound to VM's
ObservableCollection<string>
. On the right side there is a grid with two rows and two columns, the item that moves receives changes to onlyGrid.Row
andGrid.Column
properties.In order to achieve that I created Attached property which defines
TransformOperationsTransition
and subscribes to host Bounds changed event. Basically the core logic looks like this:Whenever host element changes it's position (BoundsProperty has changed) we doing the following:
plus some other neccesary stuff. The whole solution is here: https://github.com/DarthMazut/MoveTransition/tree/main
The cool part is that, whenever client wants to animate any item that changes its position is enough to:
That's it!
Now, I'm obviously not saying the current state of this solution is perfect (it has some problems), as this is just an idea accomplished overnight. But to me looks quite well consider how small XAML is needed.
Now my questions are:
Thank you for reading this post. It took me couple of hours to provide this small implementation but to me it looks quite good, so I decided to share it with you. Hoping for some feedback here, thanks :)
Beta Was this translation helpful? Give feedback.
All reactions