Skip to content

Conversation

emmauss
Copy link
Contributor

@emmauss emmauss commented Oct 1, 2025

What does the pull request do?

This PR implements #19695 .

What is the current behavior?

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0059132-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@zxbmmmmmmmmm
Copy link
Contributor

Great work!
After seeing #19695, I also tried using AttachedProperty to implement implicit animation based on Composition like this:
(I don't think it's necessary to manually add KeyFrame because it's too cumbersome)

<Rectangle
    x:Name="AnimationTarget"
    Width="100"
    Height="100"
    Fill="Red"
    local:CompositionVisualExtensions.NormalizedCenterPoint="0.5,0.5">
    <local:ImplicitAnimation.Animations>
        <local:XamlAnimationCollection>
            <local:XamlScalarAnimation TargetProperty="Opacity" Duration="0:0:0.4" />
			<local:XamlVector3Animation TargetProperty="Scale" Duration="0:0:0.4"/>
			<local:ColorKeyFrameAnimation TargetProperty="Fill" Duration="0:0:0.4"/>
        </local:XamlAnimationCollection>
    </local:ImplicitAnimation.Animations>
</Rectangle>

efe2308c964d76ffd0b56378a495ac90

But I encountered some difficulties when implementing ColorKeyFrameAnimation because we couldn't directly animate a Brush object...
I think it should be possible to have a color transition when a Brush property is changed instead of manually binding a SolidColorBrush and animate its Color.

@emmauss
Copy link
Contributor Author

emmauss commented Oct 1, 2025

Great work! After seeing #19695, I also tried using AttachedProperty to implement implicit animation based on Composition like this: (I don't think it's necessary to manually add KeyFrame because it's too cumbersome)

<Rectangle
    x:Name="AnimationTarget"
    Width="100"
    Height="100"
    Fill="Red"
    local:CompositionVisualExtensions.NormalizedCenterPoint="0.5,0.5">
    <local:ImplicitAnimation.Animations>
        <local:XamlAnimationCollection>
            <local:XamlScalarAnimation TargetProperty="Opacity" Duration="0:0:0.4" />
			<local:XamlVector3Animation TargetProperty="Scale" Duration="0:0:0.4"/>
			<local:ColorKeyFrameAnimation TargetProperty="Fill" Duration="0:0:0.4"/>
        </local:XamlAnimationCollection>
    </local:ImplicitAnimation.Animations>
</Rectangle>

efe2308c964d76ffd0b56378a495ac90 efe2308c964d76ffd0b56378a495ac90

But I encountered some difficulties when implementing ColorKeyFrameAnimation because we couldn't directly animate a Brush object... I think it should be possible to have a color transition when a Brush property is changed instead of manually binding a SolidColorBrush and animate its Color.

I don't think we have a Fill target for color. We do have Color target, but thats only for CompositionSolidColorVisual.
I also thought of using the data types as the Animation types, like you did. But with that, I think users won't know which targets are supported for which Animation type, and then they'd have to check docs for them.

@emmauss emmauss added enhancement area-xaml needs-api-review The PR adds new public APIs that should be reviewed. labels Oct 2, 2025
@zxbmmmmmmmmm
Copy link
Contributor

zxbmmmmmmmmm commented Oct 4, 2025

We do have Color target, but thats only for CompositionSolidColorVisual.

Composition brushes seem to have not been implemented in Avalonia currently, which poses significant challenges for color transition as we can only create a CompositionSolidColorVisual and animate its Color

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-xaml enhancement needs-api-review The PR adds new public APIs that should be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants