I am trying to set an image source using the pack uri like this:
<Setter.Value>
<ImageBrush ImageSource="pack://application:,,,/Resources/grid_bg.png"/>
</Setter.Value>
with a Resources.resx file like this:
with the image in it like this:
but the error I get is this:
I have also attempted this:
Pack URI and path not resolving image in WPF
and this:
At design time pack uri is valid, but not at runtime?
and this:
http://csharpsimplified.wordpress.com/2009/02/16/resources-in-wpf-i-binary-resources/
while still getting the same error as above. Somebody, please, for the love of zeus, liberate me from this menial, frustrating garbage and I will return the favor with praise and points.
In a WPF project you usually do not add image files as resources to Resource.resx. Instead you just put them into a folder in your project and set their Build Action to
Resource
, as shown below.It is also not necessary to write the Pack URI prefix. You can just write it like this:
Please note that if you add images to Resource.resx, Visual Studio generates a
Resources
class with static properties for each image. These properties are of typeSystem.Drawing.Bitmap
, which is WinForms, not WPF.