microsoft / microsoft/microsoft-ui-xaml
Element with `x:Load="False"` still evaluates `x:Bind` in C++
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
[If I understand this documentation correctly](https://learn.microsoft.com/en-us/windows/apps/develop/platform/xaml/x-load-attribute#loading-elements), when elements has `x:Load=False`, it should not evaluate `x:Bind` expression. But my getters are still called. This only happens in C++WinRT project, and does not happens in C#.
### Why is this important?
This is a major blocker for me using `x:Load` with my model, and a major discrepancy to the documentation.
### Steps to reproduce the bug
1. Create a C++winui3 project using the default template
2. Use this xaml
```xml
```
3. Use this code
```cpp
int32_t MainWindow::MyProperty()
{
OutputDebugString(L"Getter called when it is not supposed to\n");
return 42;
}
```
4. Put a breakpoint, on the line and build and run the app
5. The breakpoint is hit, and the message is printed.
The equivalent C# code is working as expected!
```cs
public int MyProperty
{
get
{
Debug.WriteLine("Getter called when it is not supposed to");
return 42;
}
}
```
### Actual behavior
_No response_
### Expected behavior
_No response_
### Screenshots
_No response_
### NuGet package version
WinUI 3 - Windows App SDK 1.8.3: 1.8.251106002
### Windows version
Windows 11 (24H2): Build 26100
### Additional context
[A full repro with both C++ and C#](https://github.com/HO-COOH/WinUI-Bug/tree/main/33-xLoadEvaluateBinding)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked 33-xLoadEvaluateBinding reproduction and compare the C++WinRT and C# projects using the shown x:Load="False" and x:Bind example. Trace when the C++ getter is invoked while the element is unloaded. Done means the C++ behavior matches the documented behavior and the C# comparison, with the getter not called.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- desktop, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100