Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Fields created for named resources have no values assigned

Open TomEdwardsEnscape opened this issue 1 year ago • 2 comments

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

TomEdwardsEnscape avatar Feb 22 '24 10:02 TomEdwardsEnscape

Resources are deferred, and I suppose it's not registered in the namescope until somebody accesses it by key once: image

maxkatz6 avatar Feb 23 '24 00:02 maxkatz6

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.

maxkatz6 avatar Feb 23 '24 00:02 maxkatz6