Let’s suppose your page contains several TextBlock elements, and you want to apply the same LinearGradientBrush to the Foreground of each of them. This is an ideal use of a resource.
The first step is to define a LinearGradientBrush in a resource section of a XAML file. If you’re defining the resource in a FrameworkElement-derivative, the resource must be defined before it is used, and it can only be accessed by the same element or a nested element.
<phone:PhoneApplicationPage.Resources> <LinearGradientBrush x:Key="brush"> <GradientStop Offset="0" Color="Pink" /> <GradientStop Offset="1" Color="SkyBlue" /> </LinearGradientBrush> </phone:PhoneApplicationPage.Resources>
Notice the x:Key attribute. Every resource must have a key name. ...