Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After having the same problem as you and doing some reading, I discovered the solution - <a href="http://msdn.microsoft.com/en-us/library/aa970069.aspx" rel="noreferrer">Pack URIs</a>.</p> <p>I did the following in code:</p> <pre><code>Image finalImage = new Image(); finalImage.Width = 80; ... BitmapImage logo = new BitmapImage(); logo.BeginInit(); logo.UriSource = new Uri("pack://application:,,,/AssemblyName;component/Resources/logo.png"); logo.EndInit(); ... finalImage.Source = logo; </code></pre> <p>Or shorter, by using another BitmapImage constructor:</p> <pre><code>finalImage.Source = new BitmapImage( new Uri("pack://application:,,,/AssemblyName;component/Resources/logo.png")); </code></pre> <p>The URI is broken out into parts:</p> <ul> <li>Authority: <code>application:///</code></li> <li><p>Path: The name of a resource file that is compiled into a referenced assembly. The path must conform to the following format: <code>AssemblyShortName[;Version][;PublicKey];component/Path</code></p> <ul> <li>AssemblyShortName: the short name for the referenced assembly.</li> <li>;Version [optional]: the version of the referenced assembly that contains the resource file. This is used when two or more referenced assemblies with the same short name are loaded.</li> <li>;PublicKey [optional]: the public key that was used to sign the referenced assembly. This is used when two or more referenced assemblies with the same short name are loaded.</li> <li>;component: specifies that the assembly being referred to is referenced from the local assembly.</li> <li>/Path: the name of the resource file, including its path, relative to the root of the referenced assembly's project folder.</li> </ul></li> </ul> <p>The three slashes after <code>application:</code> have to be replaced with commas:</p> <blockquote> <p>Note: The authority component of a pack URI is an embedded URI that points to a package and must conform to RFC 2396. Additionally, the "/" character must be replaced with the "," character, and reserved characters such as "%" and "?" must be escaped. See the OPC for details.</p> </blockquote> <p>And of course, make sure you set the build action on your image to <code>Resource</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload