Joren
Topic Author
Posts: 14
Joined: 12 Nov 2019, 15:33

Failed to use global StaticResource declared earlier

12 Nov 2019, 16:45

Hi, we have come across an issue where we are not sure if this is intended or a bug.
<!-- App.xaml-->
<Application x:Class="GameGUI.Application"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:GameGUI"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Resources/ExampleA.xaml" />
                <ResourceDictionary Source="/Resources/ExampleB.xaml" /> <!--References a StaticResource from ExampleA-->
                <ResourceDictionary Source="Resources.xaml"/>

            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
We define a StaticResource in ExampleA and reference this later in ExampleB, however it can not resolve this resource. This behaviour works in WPF (Using Blend), but doesn't when running in Noesis.

The docs state the following:
1. The lookup process checks for the requested key within the resource dictionary defined by the element that sets the property.
2. The lookup process then traverses the logical tree upward, to the parent element and its resource dictionary. This continues until the root element is reached.
3. Next, application resources are checked. Application resources are those resources within the resource dictionary that is defined by the Application object for your application.
Note that we will never reach Step 3 as we are loading our application resources at the moment, so it is not set. We believe the resource should already be resolved in Step 2. Is this intended behaviour or a bug?

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: Failed to use global StaticResource declared earlier

13 Nov 2019, 09:38

Hi Joren,

I'm sorry to say this is a known issue: #1379. Current Noesis implementation for setting Application resources requires to load the dictionary using LoadXaml before it can be set, so the behavior is different from WPF because already loaded merged dictionaries are not ready in the application to search for static resources. This is something we want to address for the next major version.

In the meantime the only workaround is to reference the resource dictionaries explicitly from the xaml that is using the resources. In your case, /Resources/ExampleB.xaml should merge the dictionary /Resources/ExampleA.xaml. If there are more dictionaries involved, what other customers are doing is to generate a chained list of merged dictionaries (A -> B -> C -> D) so static resources can be resolved, and only specify one dictionary in Application Resources.

Sorry for the inconvenience.
 
Joren
Topic Author
Posts: 14
Joined: 12 Nov 2019, 15:33

Re: Failed to use global StaticResource declared earlier

13 Nov 2019, 10:51

Hi Joren,

I'm sorry to say this is a known issue: #1379. Current Noesis implementation for setting Application resources requires to load the dictionary using LoadXaml before it can be set, so the behavior is different from WPF because already loaded merged dictionaries are not ready in the application to search for static resources. This is something we want to address for the next major version.

In the meantime the only workaround is to reference the resource dictionaries explicitly from the xaml that is using the resources. In your case, /Resources/ExampleB.xaml should merge the dictionary /Resources/ExampleA.xaml. If there are more dictionaries involved, what other customers are doing is to generate a chained list of merged dictionaries (A -> B -> C -> D) so static resources can be resolved, and only specify one dictionary in Application Resources.

Sorry for the inconvenience.
Thank you for the reply and suggestions! This clears up some of the confusion.

Who is online

Users browsing this forum: No registered users and 0 guests