Skip to content
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

AxamlRuntimeLoader breaks DynamicResources #17066

Open
racerxdl opened this issue Sep 19, 2024 · 0 comments
Open

AxamlRuntimeLoader breaks DynamicResources #17066

racerxdl opened this issue Sep 19, 2024 · 0 comments

Comments

@racerxdl
Copy link

Describe the bug

When loading a Style Axaml using the AvaloniaRuntimeLoader, any dynamic resource declared that is not in the style (a.k.a. loaded from either window resource or app resources) are resolved to null. The same axaml, if compiled works fine.

This is easily observed with a TemplatedControl being populated by a style.

To Reproduce

I added a small example to reproduce it: https://github.com/racerxdl/TemplatedControlLoadBug

There are two buttons that does a different workflow:
image

  1. Click me for the bug - Loads the custom control using AxamlRuntimeLoader, and then loads the style and replaces it. The image does not appear.
  2. Click me for no bug - Loads the exact same custom control, but let the pre-compiled style to load it. The image appears.
    private void RefreshControl()
    {
        
        var axamlData = @"<UserControl xmlns=""https://github.com/avaloniaui""
             xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
             xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
             xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006""
             xmlns:templatedControlLoadBug=""clr-namespace:TemplatedControlLoadBug""
             mc:Ignorable=""d"" d:DesignWidth=""800"" d:DesignHeight=""450"">
                <UserControl.Styles>
                    <StyleInclude Source=""TestingStyle.axaml"" />
                </UserControl.Styles>
                <templatedControlLoadBug:MagicTemplatedControl/>
            </UserControl>
        ";
        
        var assembly = Assembly.GetAssembly(GetType());
        var uri = new Uri("avares://TemplatedControlLoadBug/TestingControl.axaml");
        var obj = AvaloniaRuntimeXamlLoader.Load(axamlData, assembly, MagicContent.Child, uri) as Control;

        if (reproduceBug)
        {
            obj!.Styles.Clear();
            var avaUri = new Uri("avares://TemplatedControlLoadBug/TestingStyle.axaml");
            var styleData = (Styles)AvaloniaRuntimeXamlLoader.Load(changedStyleData, assembly, null, avaUri);
            obj.Styles.AddRange(styleData);
        }

        MagicContent.Child = obj;
    }

The style axamls are identical. Just the loading method is different.

Bugged:
image

Not bugged:
image

Expected behavior

Both methods should work.

Avalonia version

11.0.6

OS

Windows

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants