Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExpressionAnimation not work for ReferenceParameter.Offset #12939

Closed
Meloman19 opened this issue Sep 19, 2023 · 0 comments · Fixed by #13071
Closed

ExpressionAnimation not work for ReferenceParameter.Offset #12939

Meloman19 opened this issue Sep 19, 2023 · 0 comments · Fixed by #13071

Comments

@Meloman19
Copy link
Contributor

Describe the bug
Simple ExpressionAnimation that copies the Offset from one object to another does not work.

To Reproduce
Create two CompositionVisual and link their Offset properties with Expression.

1. View:
<Grid ColumnDefinitions="*, *">
   <Panel x:Name="Root1" Background="Transparent" />
   <Panel x:Name="Root2" Grid.Column="1" />
</Grid>
2. CodeBehind:
CompositionVisual rect1;
CompositionVisual rect2;

protected override void OnLoaded(RoutedEventArgs e)
{
    base.OnLoaded(e);

    rect1 = CreateSolidColorVisual(Root1);
    rect2 = CreateSolidColorVisual(Root2);

    var anim = ElementComposition.GetElementVisual(this).Compositor.CreateExpressionAnimation();
    anim.Target = "Offset";
    anim.Expression = "Source.Offset";
    anim.SetReferenceParameter("Source", rect1);

    rect2.StartAnimation("Offset", anim);

    Root1.PointerMoved += Root1_PointerMoved;
}

private CompositionVisual CreateSolidColorVisual(Visual visual)
{
    var composition = ElementComposition.GetElementVisual(visual);

    var rectangle = composition.Compositor.CreateSolidColorVisual();
    rectangle.Size = new Vector(100, 100);
    rectangle.Color = Colors.Red;

    ElementComposition.SetElementChildVisual(visual, rectangle);

    return rectangle;
}

private void Root1_PointerMoved(object? sender, Avalonia.Input.PointerEventArgs e)
{
    var pos = e.GetPosition(Root1);
    rect1.Offset = new Vector3D(pos.X, pos.Y, 0);
}
AvaloniaBehavior.mp4

Expected behavior
Both rectangles move synchronously.

For example:

WinUIBehavior.mp4

Desktop:

  • OS: Windows
  • Version 11.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants