---
title: "StaticResource and DynamicResource in WPF"  
description: "In this blog I am trying to explain the concept of StaticResource Markup Extension and DynamicResource Markup Extension in WPF.  StaticResource Markup"  
author: "Vijay Shukla"  
published: 2013-08-16  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/566/staticresource-and-dynamicresource-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# StaticResource and DynamicResource in WPF

In this blog I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [explain the concept](https://www.mindstick.com/forum/159605/explain-the-concept-of-unique-key-violation-error) of StaticResource Markup [Extension](https://www.mindstick.com/articles/22/extension-method) and DynamicResource Markup Extension in WPF.\

##### StaticResource Markup Extension

StaticResource Markup Extension Provides a value for any XAML [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) [attribute](https://www.mindstick.com/blog/221/attributes-reflection) by looking up a [reference](https://www.mindstick.com/forum/774/reference-what-does-this-error-mean-in-php) to an already defined resource. Lookup behavior for that resource is analogous to load-time lookup, which will look for [resources](https://yourviews.mindstick.com/view/293/renovation-causes-wastage-of-resources) that were previously loaded from the markup of the current XAML page [as well as](https://www.mindstick.com/interview/2481/can-you-write-a-java-class-that-could-be-used-both-as-an-applet-as-well-as-an-application) other [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) sources, and will generate that resource value as the property value in the run-time objects.

##### Syntax:-

<object property="{StaticResource key}" .../>

##### Example:-

```
<Window.Resources>
    <RadialGradientBrush x:Key="myGradientBrush">        <GradientStop Color="Green" Offset="0"/>        <GradientStop Color="Blue" Offset="2"/>    </RadialGradientBrush></Window.Resources><Grid Background="{StaticResource myGradientBrush}"></Grid>
```

##### DynamicResource Markup Extension

DynamicResource Markup Extension Provides a value for any XAML property attribute by deferring that value to be a reference to a defined resource. Lookup behavior for that resource is analogous to run-time lookup.

##### Syntax:-

```
<object property="{DynamicResource key}" .../>
```

##### \

##### Example:-

```
<Window.Resources>    <RadialGradientBrush x:Key="myGradientBrush">        <GradientStop Color="Green" Offset="0"/>        <GradientStop Color="Blue" Offset="2"/>    </RadialGradientBrush></Window.Resources><Grid Background="{DynamicResource myGradientBrush}"></Grid>
```

##### XAML Values

Key

The key for the requested resource. This key was initially assigned by the x:Key Directive if a resource was created in markup, or was provided as the key [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) when calling ResourceDictionary.Add if the resource was created in code.

---

Original Source: https://www.mindstick.com/blog/566/staticresource-and-dynamicresource-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
