简体   繁体   中英

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 exception.

Any ideas what I'm doing wrong?

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:

建立行动

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM