关于c#:为什么在运行时找不到用于图像的StaticResource?

Why isn't StaticResource for image found at runtime?

我已经在我的Resources.resx文件中添加了一个图像。 我这样引用它:

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

在设计器中,我确实在上面看到一条弯曲的蓝线。 它说

The resource"MyImage" could not be resolved.

在运行时,它将引发以下错误:

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

有什么想法我做错了吗?


不要在WPF中使用resx文件,您必须添加一些代码以使互操作工作。 resx文件中的图像主要用于WinForms代码。

在文件属性中将"构建操作"设置为"资源":

build action

然后直接引用该文件:

那里不需要{Binding}{StaticResource}