Add WinUI Expander Animation #694
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the Expander control uses the Avalonia provided CrossFade ContentTransition when expanding/collapsing. This does not match the animation in WinUI (and IMO doesn't look good anyway). SettingsExpander has also had its animations disabled in part because of this. The way Avalonia implemented animations on Expander is very rigid and previously implementing the WinUI expander animation was either extremely difficult or not possible using the existing
IPageTransition
interface. I don't feel like getting into the details as to why.To overcome this limitation and enable the animation, I am building it on as an AttachedProperty. As if we were using the normal IPageTransition, the animation is still defined in code and isn't editable, but it was built off of the WinUI xaml animation. I have also implemented it for all ExpandDirections, even though WinUI only does Down/Up.
Enabling the Animation
By default, on a regular
Expander
, the animation is opt-in since this is a stock Avalonia control and I don't know what ways its being used. There are a few ways to enable it:If you set the attached property, the value is case-insensitive however it must be equivalent to FluentV2
NOTE: if you customize the expander template and want to use this, make sure you look at the updated ControlTheme as there is a required Border that must be provided that is not part of the original template. It's
ClipToBounds
property must also be set to True to ensure correct behavior.Style
defined in App.Styles or any parent container:SettingsExpander
SettingsExpander
will have this animation on by default, and is opt-out. This has previously been requested and is not a stock Avalonia control, so I feel it is ok to make this opt-out. If you would like to opt-out, you'll set the control themeSettingsExpanderNoAnimationStyle
on any SettingsExpander you don't want the animation. The Style trick from above should apply if you want to disable for all.