Skip to content

x:bind failing to resolve some objects #10505

@dotMorten

Description

@dotMorten

Describe the bug

I'm adding AoT support to our controls library and hitting some odd behaviors for some properties when moving to x:Bind: They seem to resolve certain properties to null or not resolve at all, but if I modify the binding and undo it while hot-reload is running, it snaps out of it and starts rendering. The properties are coming from immutable objects that aren't changing, so it's not because they were null to begin with.

ReproSteps.mp4

Steps to reproduce the bug

  1. Unzip and run the following sample: toolkitrepro.zip
  2. Follow the steps shown in the above video.

Another weird behavior I've noticed: In FeatureForm.Theme.xaml if I modify the template for FieldFormElementView and change

<TextBlock Text="{x:Bind Element.Label}" Style="{StaticResource FeatureFormViewTitleStyle}"/>

to

<ContentControl Content="{x:Bind Element}">
    <ContentControl.ContentTemplate>
        <DataTemplate x:DataType="forms:FormElement">
            <TextBlock Text="{x:Bind Label}" Style="{StaticResource FeatureFormViewTitleStyle}"/>
        </DataTemplate>
    </ContentControl.ContentTemplate>
</ContentControl>

the label does resolve and render.

Also if I run the FeatureFormView sample and set a break-point in the SelectTemplateCore method src\Toolkit\Toolkit\UI\Controls\FeatureForm\FieldTemplateSelector.cs, I notice that the item parameter is null, until I do the above trick of modifying and undoing the change to the x:bind expression and hot-reload somehow makes the item property now evaluate to something.

Expected behavior

x:Bind works as old-style Bindings with would have, or as they do when hot-reload updated bindings kick in.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.7.1: 1.7.250401001

Windows version

Windows 11 (24H2): Build 26100, Windows 11 (23H2): Build 22631

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions