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:12]
smayr
swdev:dotnet:wpf:resources [2011/07/01 09:30] (current)
smayr
Line 33: Line 33:
   * See: [[swdev:dotnet:Localization Using RESX Files]]   * 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 = = 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]]