Windows icon indicating copy to clipboard operation
Windows copied to clipboard

StartAnimationAction throw exception when Animation is null

Open Lightczx opened this issue 2 years ago • 6 comments

Describe the bug

when StartAnimationAction's Animation binding to a element with ElementName which has not been "loaded", if the animation is triggered, it will throw a exception

System.ArgumentNullException: Value cannot be null. (Parameter 'Animation')

Steps to reproduce

described as above

Expected behavior

StartAnimationAction should ignore null value rather than throw a exception

Screenshots

No response

Code Platform

  • [ ] UWP
  • [X] WinAppSDK / WinUI 3
  • [ ] Web Assembly (WASM)
  • [ ] Android
  • [ ] iOS
  • [ ] MacOS
  • [ ] Linux / GTK

Windows Build Number

  • [ ] Windows 10 1809 (Build 17763)
  • [ ] Windows 10 1903 (Build 18362)
  • [ ] Windows 10 1909 (Build 18363)
  • [ ] Windows 10 2004 (Build 19041)
  • [ ] Windows 10 20H2 (Build 19042)
  • [ ] Windows 10 21H1 (Build 19043)
  • [ ] Windows 10 21H2 (Build 19044)
  • [ ] Windows 10 22H2 (Build 19045)
  • [X] Windows 11 21H2 (Build 22000)
  • [ ] Other (specify)

Other Windows Build number

No response

App minimum and target SDK version

  • [ ] Windows 10, version 1809 (Build 17763)
  • [ ] Windows 10, version 1903 (Build 18362)
  • [ ] Windows 10, version 1909 (Build 18363)
  • [X] Windows 10, version 2004 (Build 19041)
  • [ ] Windows 10, version 2104 (Build 20348)
  • [ ] Windows 11, version 22H2 (Build 22000)
  • [ ] Other (specify)

Other SDK version

No response

Visual Studio Version

2022

Visual Studio Build Number

17.7.4

Device form factor

Desktop

Additional context

No response

Help us help you

Yes, but only if others can assist.

Lightczx avatar Sep 26 '23 14:09 Lightczx

Thanks @Lightczx, can you elaborate a bit on the scenario where you see this? If you're animating on the element where the behavior is attached, it should be loaded. Since, you mention that the element hasn't been loaded yet, is this when setting a different TargetObject?

In that case, should we check if the TargetObject is Loaded and hook into its Loaded event instead to ensure any attached animation resources are also loaded to it?

Do you have a minimal set of XAML which reproduces this issue?

michael-hawker avatar Sep 27 '23 14:09 michael-hawker

I'm using this inside a ItemRepeater's ItemTemplate Somethins like this

<DataTemplate>
    <ItemContainer>
        <Border Style="{StaticResource BorderCardStyle}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <!--  Image Layer  -->
                <Border cw:UIElementExtensions.ClipToBounds="True">
                    <Border VerticalAlignment="Top" cw:VisualExtensions.NormalizedCenterPoint="0.5">
                        ...
                        <cwa:Explicit.Animations>
                            <cwa:AnimationSet x:Name="ImageZoomInAnimation">
                                <shca:ImageZoomInAnimation/>
                            </cwa:AnimationSet>
                            <cwa:AnimationSet x:Name="ImageZoomOutAnimation">
                                <shca:ImageZoomOutAnimation/>
                            </cwa:AnimationSet>
                        </cwa:Explicit.Animations>
                    </Border>
                </Border>
                ...
			</Grid>
            <mxi:Interaction.Behaviors>
                ...
                <mxic:EventTriggerBehavior EventName="PointerEntered">
                    <cwb:StartAnimationAction Animation="{Binding ElementName=ImageZoomInAnimation}"/>
                </mxic:EventTriggerBehavior>
                <mxic:EventTriggerBehavior EventName="PointerExited">
                    <cwb:StartAnimationAction Animation="{Binding ElementName=ImageZoomOutAnimation}"/>
                </mxic:EventTriggerBehavior>
            </mxi:Interaction.Behaviors>
        </Border>
    </ItemContainer>
</DataTemplate>

Lightczx avatar Sep 27 '23 15:09 Lightczx

ImageZoomIn/OutAnimation are simply classes inherited from ImplicitAnimation<string, Vector3> and change the Scale property of the applied Border

Lightczx avatar Sep 27 '23 15:09 Lightczx

I guess it's that when outside element is "loaded" the inner one is not "ready" yet. After few milliseconds when the inner element is loaded this issue is gone.

Lightczx avatar Sep 27 '23 15:09 Lightczx

@michael-hawker Any update on this?

Lightczx avatar Oct 08 '23 07:10 Lightczx

I got the same problem like this. I replaced the binding action with x:Bind on animation. Then the problem seem to be solved.

1073170482 avatar Jul 25 '24 04:07 1073170482