Example usage of UserControl.Resources in Silverlight XAML

<UserControl x: Class="MyApp.MainPage" 
 xmlns="http: //schemas. microsoft. com/winfx/2006/xaml/presentation"  
 xmlns: x="http: //schemas. microsoft. com/winfx/2006/xaml"> 
  <UserControl. Resources> 
    <LinearGradientBrush x: Key="BackgroundBrush"> 
      <LinearGradientBrush. GradientStops> 
        <GradientStop Offset="0.00" Color="Yellow" /> 
        <GradientStop Offset="0.50" Color="White" /> 
        <GradientStop Offset="1.00" Color="Purple" /> 
      </LinearGradientBrush.GradientStops> 
    </LinearGradientBrush> 
  </UserControl.Resources> 
</UserControl>

To use a resource, you use a markup extension named StaticResource:

<Grid x:Name="grid1" Background="{StaticResource BackgroundBrush}">

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.