microsoft / microsoft/microsoft-ui-xaml
`FindName` realizes an `x:Load="False"` element but leaves OneWay `x:Bind` bindings that target it permanently dead
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
If you have an element with `x:Load="False"` and another element has a OneWay `x:Bind` to its property, loading the element with `FindName` never update the binding. The binding is dead for the lifetime, **unless** adding a manual `Bindings->Update()` call.
This issue reproduces in both C++ and C#.
### Why is this important?
A OneWay binding that silently never fires is very hard to diagnose — nothing throws, nothing logs, and the XAML and code-behind both look correct. And this behavior is documented nowhere.
Note that using `x:Load` binding to a boolean value with `x:Bind` does not need the `Bindings->Update()` hack. It works in both C++ & C#, making this scenario even harder to spot.
`x:Bind` in general just has so many issues (even more so with C++/WinRT project) that at this point that I will stay away from it, even if it is supposed to give better performance than setting visibility to collapsed.
### Steps to reproduce the bug
1. Create a WinUI 3 C++/WinRT project
2. Add a `Page` (because using `x:Load` under `Window` does not work, see #9842) with this XAML
```xml
A
B
```
3. Redeclare `Box` in the idl (see #11472):
```idl
[default_interface]
runtimeclass BlankPage : Microsoft.UI.Xaml.Controls.Page
{
BlankPage();
Microsoft.UI.Xaml.Controls.ComboBox Box{ get; };
}
```
4. In the button click handler, realize the `ComboBox`
```cpp
void BlankPage::Button_Click(IInspectable const&, RoutedEventArgs const&)
{
FindName(L"Box");
}
```
5. Run the app. Click the button — the `ComboBox` appears, as expected.
6. Select **A**, then **B**, in the `ComboBox`.
### Actual behavior
The Content in the Button never appears.
### Expected behavior
The binding should update the content, so it should appear.
### Screenshots
_No response_
### NuGet package version
2.3
### Windows version
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Start with the provided Page XAML repro: a ComboBox using x:Load="False", a Button with a OneWay x:Bind, and Button_Click calling FindName("Box"). Compare the behavior in C++/WinRT and C#; done means selecting A and B updates the Button content without a manual Bindings->Update() call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100