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

Transition doesn't work when I set RenderTransform using code #17287

Open
qingyu-sama opened this issue Oct 16, 2024 · 3 comments
Open

Transition doesn't work when I set RenderTransform using code #17287

qingyu-sama opened this issue Oct 16, 2024 · 3 comments
Labels

Comments

@qingyu-sama
Copy link

Describe the bug

When I set the RenderTransform using Style , the Transition works fine

<Style Selector="Button">
    <Setter Property="Height" Value="{Binding Size}" />
    <Setter Property="Width" Value="{Binding Size}" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Foreground" Value="Transparent" />
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="VerticalAlignment" Value="Center" />
    <Setter Property="HorizontalAlignment" Value="Center" />
    <Setter Property="Opacity" Value="0" />
    <Setter Property="Transitions">
        <Transitions>
            <DoubleTransition Property="Opacity"
                              Duration="0.2"
                              Easing="QuarticEaseOut" />
            <TransformOperationsTransition Property="RenderTransform"
                                           Duration="0.2"
                                           Easing="QuarticEaseOut" />
        </Transitions>
    </Setter>
</Style>
<Button Classes.open="{Binding IsOpen}">
    <Button.Styles>
        <Style Selector="Button.open">
            <Setter Property="RenderTransform" Value="translateX(78px)" />
        </Style>
    </Button.Styles>
    <Image Source="..." />
</Button>

floatingBar

But when I set the RenderTransform using code instead, the Transition works in a weird way, including the DoubleTransition of Opacity

for (var i = 0; i < Container.Children.Count; i++) {
    var child = Container.Children[i];

    if (data.IsOpen)
        child.RenderTransform = new TranslateTransform((i + 1) * FloatingBarViewModel.Size, 0);
    else
        child.RenderTransform = new TranslateTransform();
}

floatingBar2

To Reproduce

As mentioned above

Expected behavior

No response

Avalonia version

11.2.0-rc1

OS

Windows, Android

Additional context

No response

@timunie
Copy link
Contributor

timunie commented Oct 16, 2024

Try child.SetValue or SetCurrentValue

@maxkatz6
Copy link
Member

From what I remember, XAML transform value is actually emit as new TransformOperations.Builder(1).AppendTranslate(78, 0).Build(), which had different transition rules.

@timunie
Copy link
Contributor

timunie commented Oct 17, 2024

This seems to work:

private void Button_OnClick(object? sender, RoutedEventArgs e)
{
    if (sender is Button btn)
    {
        var builder = new TransformOperations.Builder(1);
        builder.AppendTranslate(78, 0);
        
        btn.RenderTransform = builder.Build();
    }
}

@maxkatz6 do you think this is by design?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants