-
Notifications
You must be signed in to change notification settings - Fork 711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lack of notification for x:Load #10405
Comments
This may be a a misunderstand of what it is trying to say. This is an example of what the docs are saying:
In your case, specifying the |
Hmmmm, thanks for this! What happens if the x:Load’d element is in, say, a Grid? This is often the case. I notice that Grid.Children is a UIElementCollection, which does not implement CollectionChanged. Again, it would seem that if I name the x:Load element and x:Bind to it or use a Binding to it then the binding will not be updated. In other words, the comment about Border.Child being notified is a partial answer. It does not address how to get a notification of x:Load occurring for elements contained in a panel. This also does not provide a way to discover, say from code-behind, an element that can be listened to for the notification. The added comment about specifying Loaded event on the x:Load element (the Rectangle) in XAML is interesting. I haven't tried this yet. This must be something specific to the XAML interpretation of event handlers, because in code-behind obviously I can't subscribe to the Rectangle's Loaded event when I don't have a reference to the Rectangle (which, presumably, has not even been created when the containing control is created). My use case is listening for property changes in a c# library, rather than customized XAML code. |
x:Bind generated code will manually hook up XAML events when realising an object for you |
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
The text was updated successfully, but these errors were encountered: