1

I've looked at about a dozen different solutions to get this to work and I just can't seem to execute it properly. I have a file cup.png that I placed in a subfolder called /Images/ located in my project folder under "/Visual Studio 2013\Projects\PointOfSale\PointOfSale\Images\cup.png".

The IDE acts like it can find the file and it shows up in the designer view and everything, and I can compile, but the minute I run it I get a XamlParseException error:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll Additional information: 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '7' and line position '14'.

What in the world am I missing here? I've tried all different forms of these to try and get this to work:

<ImageBrush ImageSource="pack://application:,,,/PointOfSale;component/cup.png" Opacity="0.1"/>
<ImageBrush ImageSource="/cup.png" Opacity="0.1"/>
<ImageBrush ImageSource="/Images/cup.png" Opacity="0.1"/>
<ImageBrush ImageSource="/PointOfSale;component/Images/cup.png" Opacity="0.1"/>
Logan Wayne
  • 6,001
  • 16
  • 31
  • 49
Jesse Cleary
  • 123
  • 1
  • 7
  • Do you want the image embedded within the binary, or as an external resource in a folder relative to the executable? – myermian Sep 07 '15 at 00:02
  • Basically, I need to zip the whole solutions folder and send it to someone, and I want to make sure the program can load the image file as it is the background image for the main window. I need it to load the file from some folder in the solution folder without it needing the whole path (C:\users\...\documents\visual studio\etc....) – Jesse Cleary Sep 07 '15 at 00:07

1 Answers1

2

You have a couple of options (your response to my comment did not answer this directly)

  1. You can include the images as a resource using the BuildAction of Resource.
  2. You can include the images as a piece of content using the BuildAction of Content.

If you choose the first option, then replacing the image would require the entire assembly/executable to be replaced. You can reference the image as "assembly;component/Resources/Images/cup.png" (Note that you need a forward slash at the start of the string).

If you choose the second option, then replacing the image would require you to merely replace the image file. You can reference the image as "/Resources/Images/darkaurora.png" (Note that you need a forward slash at the start of the string).

myermian
  • 31,823
  • 24
  • 123
  • 215
  • Finally....FINALLY got it to work with your suggestion of changing it to BuildAction Content. Thank you so much. – Jesse Cleary Sep 07 '15 at 01:21
  • @JesseCleary If you ever need to go the route of embedding the image in a resource file then I've had this issue in the past and this should be of assistance: [*Pack URI to image embedded in a resx file*](http://stackoverflow.com/q/16409819/109702) – slugster Sep 07 '15 at 01:47