Skip to content

Storyboard.TargetName that does not resolve in scope breaks the build instead of no-op'ing #24432

Closed

Description

@MartinZikmund

Current behavior 🐛

A Storyboard.TargetName that does not resolve to an element declared in the same XAML scope makes the build fail, instead of being ignored at runtime.

The XAML generator emits a compile-time reference to a generated subject field for every Storyboard.TargetName
(XamlFileGenerator.cs, the member.Member.Name == "TargetName" branch):

Storyboard.SetTargetName(target, "FocusVisualWhite");
Storyboard.SetTarget(target, _FocusVisualWhiteSubject);   // CS0103 when no such element exists

WinUI resolves the target name lazily at runtime and simply does not animate when it cannot be resolved. Uno's own
Timeline already behaves that way — it logs at Debug ("Failed to find target …") and returns null — so only the
generator is strict.

This is not a hypothetical: WinUI's own generic.xaml ships a MediaTransportControls Focused visual state whose
storyboard targets FocusVisualWhite / FocusVisualBlack, neither of which exists in that template. Importing that
XAML verbatim therefore does not build, and the storyboard has to be commented out by hand.

Expected behavior 🎯

An unresolvable Storyboard.TargetName should produce a warning at build time (or nothing at all) and no-op at runtime,
matching WinUI. It should not break compilation.

How to reproduce it (as minimally and precisely as possible) 🔬

Put this in any page:

<Grid>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="States">
            <VisualState x:Name="Some">
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="NotInThisTemplate"
                                     Storyboard.TargetProperty="Opacity"
                                     To="1" Duration="0" />
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
</Grid>

The build fails with CS0103: The name '_NotInThisTemplateSubject' does not exist in the current context.

Workaround 🛠️

Comment out the offending storyboard, or add a placeholder element carrying the referenced x:Name.

Renderer 🎨

  • Skia

Affected platforms 📱💻🖥️

Build tasks

Anything else we need to know? 💬

Found while importing WinUI's generic.xaml wholesale (#12839). Every future WinUI XAML import will hit this, so
handling it in the generator removes a recurring manual patch step.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions