0

I tried to load an image into my WPF project's main window. First I created RESX file called Images.resx (it's in Properties folder). Then I added an image called logo.png into this resource (using VS2010 RESX editor). Images were correctly copied into Resource folder. Then I changed Build Action property from Embedded Resource to Resource. After this I wanted to load my image in XAML.

<Image x:Name="image" Source="/MyProject;component/Resources/Logo.png" />

An image appeared in the preview in Expression Blend but when I compile the program, there is an empty window (without images).

Next I used ResourceDictionary. I created new file - Theme.xaml and added this:

<BitmapImage x:Key="logo" UriSource="/MyProject;component/Resources/Logo.png" />

And in MainWindow.xaml:

    <Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Styles/Theme.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>
<Image x:Name="image" Source="{StaticResource logo}" />

Again OK in Expression Blend but after compilation... Nothing appears:/

I tried to change back Build Action to Embedded Resource. Nothing happened.

Could anyone tell me how to use embedded resource from RESX file in XAML? Thanks in advance.

H.B.
  • 166,899
  • 29
  • 327
  • 400
Nickon
  • 9,652
  • 12
  • 64
  • 119
  • Related: http://stackoverflow.com/questions/8062221/images-bound-to-images-added-to-resx-files-using-xaml/8064281#8064281 – H.B. Mar 06 '12 at 15:56
  • Why do you add them to a resx in the first place? Do you localize them? If so, why then use absolute paths? – H.B. Mar 06 '12 at 15:56

1 Answers1

0

Ok. I found the answer... When I add some image into my RESX file, then it appears in Resource folder. Now I have to change Build Action of my RESX file AND IMAGES IN RESOURCES FOLDER

Nickon
  • 9,652
  • 12
  • 64
  • 119