microsoft / microsoft/microsoft-ui-xaml
x:bind failing to resolve some objects
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### 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.
https://github.com/user-attachments/assets/2867969f-f03c-4f74-add5-ac6f861a671b
### Steps to reproduce the bug
1. Unzip and run the following sample: [toolkitrepro.zip](https://github.com/user-attachments/files/19687673/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
```xml
```
to
```xml
```
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_
Contributor guide
Research direction
Start by running the toolkitrepro.zip sample and reproducing the binding failure described in FeatureForm.Theme.xaml. Inspect FieldTemplateSelector.cs, especially SelectTemplateCore, while comparing the direct x:Bind expression with the ContentControl/DataTemplate workaround. Done means immutable object properties and the template item resolve without requiring a hot-reload edit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- desktop-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100