Feldruebe
Topic Author
Posts: 20
Joined: 24 Jun 2018, 11:52

Static resource not found error

14 Dec 2023, 22:38

Hello,
I am getting an error that a static resource can not be found when using it in a DataTemplate defined in another resource dictionary. But it still works fine.
I can fix this by moving the dictionary below. Is this normal?

Error:
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="clr-namespace:Phase1.Ui.Overlay.Converters">

    <ResourceDictionary.MergedDictionaries>
         <ResourceDictionary Source="SkillInfoTemplates.xaml" />

        <ResourceDictionary>
            <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
        </ResourceDictionary> 
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
No Error:
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="clr-namespace:Phase1.Ui.Overlay.Converters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
            <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
        </ResourceDictionary> 
        
        <ResourceDictionary Source="SkillInfoTemplates.xaml" />
    </ResourceDictionary.MergedDictionaries>   
</ResourceDictionary>
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: Static resource not found error

15 Dec 2023, 12:39

Hello,

StaticResources can only be resolved if they can be found in the Application Resources or if they are defined before in the same xaml, so the order matters.

I guess the dictionary you posted is used as the Application Resources. This makes possible that resources defined in previously merged dictionaries are also available to the following merged dictionaries:

AppResources.xaml
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
         <ResourceDictionary Source="A.xaml" />
         <ResourceDictionary Source="B.xaml" />
    </ResourceDictionary.MergedDictionaries>    
</ResourceDictionary>
In this example, if AppResources.xaml is used as the Application Resources, dictionary B can use resources from A. But not on the other direction, dictionary A can't use resources from B.

Who is online

Users browsing this forum: No registered users and 1 guest