Each resource in a resource dictionary must have a unique key.
When you define resources in markup, you assign the unique key through the x: Key Directive.
A resource is an object that can be reused in different places in your application. This overview describes how to use resources in XAML.
For more information about markup extension behavior, see Markup Extensions and WPF XAML.When you use a markup extension, you typically provide one or more parameters in string form that are processed by that particular markup extension, rather than being evaluated in the context of the property being set.The Static Resource Markup Extension processes a key by looking up the value for that key in all available resource dictionaries.This happens during loading, which is the point in time when the loading process needs to assign the property value that takes the static resource reference.The Dynamic Resource Markup Extension instead processes a key by creating an expression, and that expression remains unevaluated until the application is actually run, at which time the expression is evaluated and provides a value.
When you reference a resource, the following considerations can influence whether you use a static resource reference or a dynamic resource reference: Static resource references from within a resource dictionary must reference a resource that has already been defined lexically before the resource reference.In the previous example, the same resource sets two different properties: the Background of a Button, and the Fill of a Rectangle.A resource can be referenced as either a static resource or a dynamic resource.Typically, the key is a string; however, you can also set it to other object types by using the appropriate markup extensions.Nonstring keys for resources are used by certain feature areas in WPF, notably for styles, component resources, and data styling.The example then references the resource and uses it to set properties of several child elements, including an Ellipse, a Text Block, and a Button.