Nested resources in Silverlight XAML

In the code below, the style ButtonStylee is nested within the stackpanel. Silverlight will be able to find the nested style since it looks at resources recursively.

<UserControl x: Class="MyApp.ResourceHierarchy" 
 xmlns="http: //schemas. microsoft. com/winfx/2006/xaml/presentation"  
 xmlns: x="http: //schemas. microsoft. com/winfx/2006/xaml"  
 Width="400" Height=" 300"> 
  <Grid x: Name="LayoutRoot" Background="White"> 
        <LinearGradientBrush x: Key="ButtonStylee"> 
          <GradientStop Offset="0.00" Color=" Yellow" /> 
          <GradientStop Offset="0.50" Color="White" /> 
          <GradientStop Offset="1.00" Color="Purple" />
      </StackPanel. Resources> 
      <Button Content=" Click Me First" Margin=" 5" 
       Background=" {StaticResource ButtonStylee}" ></Button> 
      <Button Content=" Click Me Next" Margin="5" 
       Background=" {StaticResource ButtonStylee}" ></Button> 

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.