Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:wpf:resources [2011/07/01 09:10]
smayr
swdev:dotnet:wpf:resources [2011/07/01 09:30] (current)
smayr
Line 1: Line 1:
-== Resources ==+= Resources =
  
-=== Embedding an Application Icon ===+== Embedding an Application Icon ==
  
   * Create App.rc: <code>   * Create App.rc: <code>
Line 14: Line 14:
 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).
Line 30: Line 30:
 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.
  
-=== Localization using Resources === +== Localization using Resources == 
-  * See [[swdev:dotnet:localization_using_resx_files]]+  * See[[swdev:dotnet:Localization Using RESX Files]]
  
-== References ==+== 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]]