Live Chat Icon For mobile
Live Chat Icon

How can I use an application resource ?

Platform: WPF| Category: Resources

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.

  <Style TargetType='Button' x:Key='GelButton' >
    <Setter Property='Margin' Value='1,2,1,2'/>
    <Setter Property='HorizontalAlignment' Value='Left'/>
    <Setter Property='Template'>



The following example shows an 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 the 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.


<Button Height='50' Width='250' Style='{StaticResource GelButton}' Content='Button 1' />
<Button Height='50' Width='250' Style='{StaticResource GelButton}' Content='Button 2' />

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.