0
votes

I wrote a custom ResourceDictionary that implements theme support in the exact same way: by loading the appropriate theme dictionary depending on the light/dark theme.

 <ApplicationName:ThemeResourceDictionary.LightResources>
                <ResourceDictionary Source="/ApplicationName;component/Resources/Light.xaml"/>
</ApplicationName:ThemeResourceDictionary.LightResources>

<ApplicationName:ThemeResourceDictionary.DarkResources>
    <ResourceDictionary Source="/ApplicationName;component/Resources/Dark.xaml"/>
</ApplicationName:ThemeResourceDictionary.DarkResources>

Stylr file:

<ResourceDictionary  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">    
<BitmapImage x:Key="Logo62"  UriSource="/ApplicationName;component/icon_62_dark.png" />   

On my XAML page I use it like

<Image Source="{StaticResource Logo62}" Margin="0,4,10,0"/>

when I run the application all works well but in Expression Bland i have an error: "The resource "Logo62" could not be resolved" and I do not see this image. Could anybody help me how to fix this issue.

1

1 Answers

0
votes

Try changing your resource dictionary to this:

<ResourceDictionary  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">    
<BitmapImage x:Key="Logo62"  UriSource="/icon_62_dark.png" /> 

Note that I removed the /ApplicationName;component/

Otherwise you'll have to change the image build action in Visual Studio to Resource instead of Content, otherwise the file won't be build and included in the project correctly.