locked
Image from resource to display in UI using XAML and code file... RRS feed

  • Question

  • Hello All,

    I have few images which are used across various projects. I want to add these images as a resource in one my DLL project and let all other projects use this resource DLL to display images in UI.

    How i can create a image resource only DLL library? And how i can use these images from a code behind file and in XAML to display in UI?

    Finally is this the best way to load images from resources to display in UI?

    Thanks in advance,

    IamHuM

    Thursday, December 26, 2013 2:17 PM

Answers

  • Hi. You could create a new class library project and add the images as resources to that project. Then you can use PACK URIs to reference the images in your WPF projects. 
    Thursday, December 26, 2013 2:47 PM
  • Hi. You could create a new class library project and add the images as resources to that project. Then you can use PACK URIs to reference the images in your WPF projects. 

    Agree

    The pack URI for a resource file that is compiled into a referenced assembly uses the following authority and path:

    • Authority: application:///.

    • Path: The name of a resource file that is compiled into a referenced assembly. The path must conform to the following format:

      AssemblyShortName[;Version][;PublicKey];component/Path

      • AssemblyShortName: the short name for the referenced assembly.

      • ;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.

      • ;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.

      • ;component: specifies that the assembly being referred to is referenced from the local assembly.

      • /Path: the name of the resource file, including its path, relative to the root of the referenced assembly's project folder.

    The following example shows the pack URI for a XAML resource file that is located in the root of the referenced assembly's project folder.

    pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml

    The following example shows the pack URI for a XAML resource file that is located in a subfolder of the referenced assembly's project folder.

    pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml

    The following example shows the pack URI for a XAML resource file that is located in the root folder of a referenced, version-specific assembly's project folder.

    pack://application:,,,/ReferencedAssembly;v1.0.0.1;component/ResourceFile.xaml

    Note that the pack URI syntax for referenced assembly resource files can be used only with the application:/// authority. For example, the following is not supported in WPF.

    pack://siteoforigin:,,,/SomeAssembly;component/ResourceFile.xaml


    Best Regards,
    Please remember to mark the replies as answers if they help

    Friday, December 27, 2013 6:57 AM

All replies

  • Hi. You could create a new class library project and add the images as resources to that project. Then you can use PACK URIs to reference the images in your WPF projects. 
    Thursday, December 26, 2013 2:47 PM
  • Hi. You could create a new class library project and add the images as resources to that project. Then you can use PACK URIs to reference the images in your WPF projects. 

    Agree

    The pack URI for a resource file that is compiled into a referenced assembly uses the following authority and path:

    • Authority: application:///.

    • Path: The name of a resource file that is compiled into a referenced assembly. The path must conform to the following format:

      AssemblyShortName[;Version][;PublicKey];component/Path

      • AssemblyShortName: the short name for the referenced assembly.

      • ;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.

      • ;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.

      • ;component: specifies that the assembly being referred to is referenced from the local assembly.

      • /Path: the name of the resource file, including its path, relative to the root of the referenced assembly's project folder.

    The following example shows the pack URI for a XAML resource file that is located in the root of the referenced assembly's project folder.

    pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml

    The following example shows the pack URI for a XAML resource file that is located in a subfolder of the referenced assembly's project folder.

    pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml

    The following example shows the pack URI for a XAML resource file that is located in the root folder of a referenced, version-specific assembly's project folder.

    pack://application:,,,/ReferencedAssembly;v1.0.0.1;component/ResourceFile.xaml

    Note that the pack URI syntax for referenced assembly resource files can be used only with the application:/// authority. For example, the following is not supported in WPF.

    pack://siteoforigin:,,,/SomeAssembly;component/ResourceFile.xaml


    Best Regards,
    Please remember to mark the replies as answers if they help

    Friday, December 27, 2013 6:57 AM