4thSpace 4thSpace - 1 year ago 74
C# Question

Why isn't StaticResource for image found at runtime?

I've added an image to my Resources.resx file. I reference it like this:

<Image Source="{Binding MyImage}"/>

In the designer, I do see a squiggly blue line under the above. It says

The resource "MyImage" could not be resolved.

At runtime, it throws this error:

Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an

Any ideas what I'm doing wrong?

Answer Source

Don't use resx files with WPF, you'd have to add some code to make the interop work. Images in resx files are primarily used for WinForms code.

Set the Build Action to Resource in the file properties:

build action

Then just reference the file directly: <Image Source="../../Some/Relative/Path.png"/>

Neither {Binding} nor {StaticResource} is needed there.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download