Both sides previous revision
Previous revision
Next revision
|
Previous revision
|
swdev:dotnet:wpf:resources [2011/04/25 14:00] smayr |
swdev:dotnet:wpf:resources [2011/07/01 09:30] (current) smayr |
== Resources == | = Resources = |
| |
=== Embedding an Application Icon === | == Embedding an Application Icon == |
| |
* Create App.rc: <code> | * Create App.rc: <code> |
101 ICON "Application.ico" | 101 ICON "images\\Application.ico" |
102 ICON "Document.ico" | 102 ICON "images\\Document.ico" |
103 ICON "Help.ico"</code> | 103 ICON "images\\Help.ico"</code> |
* Compile:<code>C:\> rc App.rc </code> | * Compile using Resource Compiler (Visual Studio Command Line):<code>C:\> rc App.rc </code> |
* Add ''App.res'' to the project (leave ''None'' as the ''Build Action''). | * Add ''App.res'' to the project (leave ''None'' as the ''Build Action''). |
| * Select icon for project: Project > Properties > Application > Resources: Icon and Manifest. |
* Build. | * Build. |
| |
Source: [[http://stackoverflow.com/questions/1832583/embed-multiple-icons-in-wpf-exe|StackOverflow: Dmitry Schechtman, "Embed multiple icons in WPF EXE"]] | Source: [[http://stackoverflow.com/questions/1832583/embed-multiple-icons-in-wpf-exe|StackOverflow: Dmitry Schechtman, "Embed multiple icons in WPF EXE"]] |
| |
=== Referencing Resources from an Assembly === | == 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). | 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). |
NOTE: Make sure the image file is compiled as ''Resource'' (not ''Embedded Resource'' or ''Content'') in the assembly. | NOTE: Make sure the image file is compiled as ''Resource'' (not ''Embedded Resource'' or ''Content'') in the assembly. |
| |
== References == | == Localization using Resources == |
| * See: [[swdev:dotnet:Localization Using RESX Files]] |
| |
| == Resource Dictionary == |
| |
| ==== ResourceDictionary in Application ==== |
| * Create a resource dictionary using XML. Eg: ''Assets\FormDictionary.xaml'': <code 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"> |
| |
| <!--Control colors.--> |
| <Color x:Key="WindowColor">#FFE8EDF9</Color> |
| <Color x:Key="ContentAreaColorLight">#FFC5CBF9</Color> |
| <Color x:Key="ContentAreaColorDark">#FF7381F9</Color> |
| . . . |
| </ResourceDictionary> |
| </code> |
| |
| |
| ==== ResourceDictionary Assembly ==== |
| * Create an assembly project in C#. |
| * Add references to: |
| * ''PresentationCore'' |
| * ''PresentationFramework'' |
| * ''WindowsBase'' |
| * Create a resource dictionary using XML: <code 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> |
| </code> |
| |
| ==== Merge ResourceDictionary at Application Scope ==== |
| |
| ''ResourceDictionary'' files can be merged together in ''App.xaml'' so these resource are available for all controls in the application: |
| <code xml> |
| <Application |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| x:Class="MyApp"> |
| <Application.Resources> |
| <ResourceDictionary> |
| <ResourceDictionary.MergedDictionaries> |
| <ResourceDictionary Source="Assets/FormDictionary.xaml" /> |
| <ResourceDictionary Source="AHI.App.Resources;component/MainDictionary.xaml" /> |
| </ResourceDictionary.MergedDictionaries> |
| </ResourceDictionary> |
| </Application.Resources> |
| </Application> |
| </code> |
| = References = |
* [[http://msdn.microsoft.com/en-us/library/aa970069.aspx|MSDN: Pack URIs in WPF]] | * [[http://msdn.microsoft.com/en-us/library/aa970069.aspx|MSDN: Pack URIs in WPF]] |
| * [[http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/03/creating-and-consuming-resource-dictionaries-in-wpf-and-silverlight.aspx|MSDN Blogs: Creating and Consuming Resource Dictionaries in WPF and Silverlight]] |