This kind of resource gives back a value of a resource. Listing
1 shows a simple example of static resource.
Listing 1
<Window x:Class="ResourcesInXAML.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Resources In XAML" Height="200" Width="300"
>
<Window.Resources>
<SolidColorBrush x:Key="myBrush" Color="GreenYellow" />
</Window.Resources>
<Button Background="{StaticResource myBrush}"
Width="200" Height="40" Name="myButton">
ASP Alliance
</Button>
</Window>
As I stated in the introduction, resource management is a
part of the Windows Presentation Foundation so you do not need to use the "x:"
prefix to refer to it.
If you want to implement static resources in code, their
code equivalent is FindResource method for elements. Listing 2 shows this in
action.
Listing 2
myButton.Background =
(Brush)myButton.FindResource("myBrush");
Note that, as the name suggests, a static resource is useful
for scenarios in which you want to get the value for a static value. If you
want to retrieve the value for a dynamic value (a value that changes on
runtime), dynamic resource is your choice because static resource will not be
updated on runtime to specify any change.