|I am trying to create a user control in a WPF application that includes a
BitmapImage that has been added to the project by including it in Resources.resx. In the xaml editor using VS 2012 I can put the cursor inside the
BitmapImage tag, and then reference the properties of the BitmapImage from the editor's properties pane.
UriSource dropdown box I can see all of the resources that I have added to the application including those images that are included in Resources.resx, but when I add one of the images and run the program, an exception is raised referencing the line in the xaml where the
BitmapImage control is defined.
For example if I start with this:
<BitmapImage x:Key="CameraImage" CreateOptions="IgnoreImageCache" CacheOption="OnLoad" />
And use properties pane to select the image I want from the
UriSource field, this attribute is added:
From what I can tell this
URI references a file that should be on the drive in the "Resources" directory below the point from which the application runs. If so, I understand why this would produce an error, since that directory does not exist where the application runs (and is not supposed to).
From the documentation I have seen, if a resource is embedded in the local assembly (i.e., the exe file), that the right
URI should be something like this:
siteoforigin" is replaced with "
application." But that does not seem to work for me either.
The exceptions I see differ depending on different modifications I've made to this attribute's value. The last one referenced gives me a
XamlParseException with a message saying, "'Initialization of 'System.Windows.Media.Imaging.BitmapImage' threw an exception," and it had an inner
IOException with a message of "Cannot locate resource 'resources/camera32x32.png'." The
siteoforigin syntax also throws a
XamlParseException, but the inner exception is a
DirectoryNotFoundException, and says "Could not find a part of the path."
I have tried several things without luck here, and I've run out of ideas. Can someone help to point me down the right path, and tell me how I can reference an embedded resource from a xaml page?