Avalonia
Avalonia copied to clipboard
Fields created for named resources have no values assigned
Paste the following XAML into any window:
<Window.Resources>
<Panel Name="MyPanel" x:Key="MyPanel"/>
</Window.Resources>
Then execute the following code in its constructor:
InitializeComponent();
Debug.Assert(MyPanel != null);
The assertion will fail.
Expected behavior
Either no field is created for MyPanel, or the field is correctly populated by InitializeComponent.
Environment
- OS: Windows
- Avalonia-Version: 11.0.9
Resources are deferred, and I suppose it's not registered in the namescope until somebody accesses it by key once:
Also, from DeferredTransformationFactoryV2 implementation, it always uses ChildNameScope for deferred content, so it's not even populated back into the parent one, which makes sense.
I suppose the easiest and still reasonable fix would be to disable deferred resources, if they have x:Name on them.