You are on page 1of 2

12/19/13

How to: Use Application Resources

How to: Use Application Resources


.NET Framework 4.5 This example shows how to use application resources.

Example
The following example shows an application definition file. The application definition file defines a resource section (a value for the Resources property). Resources defined at the application level can be accessed by all other pages that are part of the application. In this case, the resource is a declared style. Because a complete style that includes a control template can be lengthy, this example omits the control template that is defined within the ContentTemplate property setter of the style. XAML < A p p l i c a t i o n . R e s o u r c e s > < S t y l eT a r g e t T y p e = " B u t t o n "x : K e y = " G e l B u t t o n "> < S e t t e rP r o p e r t y = " M a r g i n "V a l u e = " 1 , 2 , 1 , 2 " / > < S e t t e rP r o p e r t y = " H o r i z o n t a l A l i g n m e n t "V a l u e = " L e f t " / > < S e t t e rP r o p e r t y = " T e m p l a t e " > < S e t t e r . V a l u e >

. . .

< / S e t t e r . V a l u e > < / S e t t e r > < / S t y l e > < / A p p l i c a t i o n . R e s o u r c e s > The following example shows a XAML page that references the application-level resource that the previous example defined. The resource is referenced by using a StaticResource Markup Extension that specifies the unique resource key for the requested resource. No resource with key of "GelButton" is found in the current page, so the resource lookup scope for the requested resource continues beyond the current page and into the defined application-level resources. XAML < S t a c k P a n e l N a m e = " r o o t " x m l n s = " h t t p : / / s c h e m a s . m i c r o s o f t . c o m / w i n f x / 2 0 0 6 / x a m l / p r e s e n t a t i o n " x m l n s : x = " h t t p : / / s c h e m a s . m i c r o s o f t . c o m / w i n f x / 2 0 0 6 / x a m l " > < B u t t o nH e i g h t = " 5 0 "W i d t h = " 2 5 0 "S t y l e = " { S t a t i c R e s o u r c eG e l B u t t o n } "C o n t e n t = " B u t t o n1 "/ > < B u t t o nH e i g h t = " 5 0 "W i d t h = " 2 5 0 "S t y l e = " { S t a t i c R e s o u r c eG e l B u t t o n } "C o n t e n t = " B u t t o n2 "/ > < / S t a c k P a n e l >

See Also
msdn.microsoft.com/en-us/library/ms746624(d=printer,v=vs.110).aspx 1/2

12/19/13

How to: Use Application Resources

Concepts
XAML Resources Application Management Overview

Other Resources

Resources How-to Topics

2013 Microsoft. All rights reserved.

msdn.microsoft.com/en-us/library/ms746624(d=printer,v=vs.110).aspx

2/2

You might also like