This is an old revision of the document!


Resources
Embedding an Application Icon
  • Create App.rc:
    101 ICON "images\\Application.ico"
    102 ICON "images\\Document.ico"
    103 ICON "images\\Help.ico"
  • Compile using Resource Compiler (Visual Studio Command Line):
    C:\> rc App.rc 
  • Add App.res to the project (leave None as the Build Action).
  • Select icon for project: Project > Properties > Application > Resources: Icon and Manifest.
  • Build.

Source: StackOverflow: Dmitry Schechtman, "Embed multiple icons in WPF EXE"

Referencing Resources from an Assembly

In XAML, to reference an image in images/icons/icon-product-acme1.png in assembly Acme.Products.Specifications.dll, you need to use the pack notation (for package).

Local Assembly (no pack notation required):

<Image Source="/images/icons/icon-product-acme1.png" Width="35" Height="35" Margin="5" />

Referenced Assembly:

<Image Source="pack://application:,,,/Acme.Products.Specifications;component/images/icons/icon-product-acme1.png" Width="35" Height="35" Margin="5" />

NOTE: Make sure the image file is compiled as Resource (not Embedded Resource or Content) in the assembly.

Localization using Resources
Resource Dictionary
  • Create an assembly project in C#.
  • Add references to:
    • PresentationCore
    • PresentationFramework
    • WindowsBase
  • Create a resource dictionary using XML:
    <ResourceDictionary 
                 xmlns:sys="clr-namespace:System;assembly=mscorlib"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:p="clr-namespace:AHI.App.Localization;assembly=AHI.App.Localization">
     
        <!--Control colors.-->
        <Color x:Key="WindowColor">#FFE8EDF9</Color>
        <Color x:Key="ContentAreaColorLight">#FFC5CBF9</Color>
        <Color x:Key="ContentAreaColorDark">#FF7381F9</Color>
        . . .
    </ResourceDictionary>
References