Skip to content

Lack of notification for x:Load #10405

@sjb-sjb

Description

@sjb-sjb

Describe the bug

The page on x:Load 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageIssue needs to be triaged by the area owners

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions