microsoft / microsoft/microsoft-ui-xaml
Lack of notification for x:Load
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
The [page on x:Load](https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/x-load-attribute) says that when the deferred element is loaded, “If you have registered to receive property change notifications on the property containing the deferred element(s), the notification is raised.”
But it also says that “The field for x:Name is set.” And indeed, the XAML element that has x:Load and x:Name is declared as a field with the specified name, not as a dependency property. So, actually there is no "property containing the deferred element(s)". And obviously you cannot subscribed to the Loaded event of an element whose field reference is null.
In other words, as far as I can tell there is actually no way to receive a change notification when a deferred element using x:Load is loaded. This breaks various types of code where an action must be taken when an element is loaded. For example, triggering a piece of code-behind to examine a property of the deferred element is not really possible since no notification is raised when the element is loaded.
It is not always possible to detect the condition that triggered the loading. For example, when the control containing the x:Load element is a parameter to a library method. As well, if x:Load is bound to a path and one attempts to trigger a notification of the load using a separate binding based on the same path, then there is a race condition between the two bindings.
### Steps to reproduce the bug
Create a XAML user control and specify x:Load on one of the elements in the user control. Then, try to get a notification of the element being loaded. No can do!
### Expected behavior
There should be a mechanism for raising a notification when x:Load is triggered to load the element.
### Screenshots
_No response_
### NuGet package version
None
### Windows version
_No response_
### Additional context
_No response_
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 by reproducing the issue with a XAML user control containing an x:Load element and review the linked x:Load documentation. The work is complete when a supported mechanism reliably notifies code when the deferred element loads, including when loading is triggered through a binding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100