Friday, February 6, 2009

Blue Gradient in XAML

I'll show a custom color gradient in XAML.
Note that it's slightly different declaration and usage in Silverlight 2.0 and in WPF (or Windows Presentation Foundation) 3.5 SP1.

Here is the XAML in Silverlight (Page.xaml):
< UserControl.Resources>
< LinearGradientBrush x:Key="LightBlue4Background" EndPoint="0.5,1" StartPoint="0.5,0">
< GradientStop Color="#FF6C83D8" Offset="0"/>
< GradientStop Color="#FFEDEFF6" Offset="0.25"/>
< GradientStop Color="#FFA4AED6" Offset="0.75"/>
< GradientStop Color="#FF0B3EFF" Offset="1"/>
< /LinearGradientBrush>
< /UserControl.Resources>

Here's how to use it in Silverlight 2.0:
< Canvas x:Name="uxcLayoutRoot" Background="{StaticResource LightBlue4Background}">
< TextBox x:Name="uxtDid" Background="{StaticResource LightBlue4Background}"/>
< /Canvas>

Here is the XAML in WPF 3.5 SP1 (MyAppName.xaml):
< Window.Resources>
< LinearGradientBrush x:Key="LightBlue4Background" EndPoint="0.5,1" StartPoint="0.5,0">
< GradientStop Color="#FF6C83D8" Offset="0"/>
< GradientStop Color="#FFEDEFF6" Offset="0.25"/>
< GradientStop Color="#FFA4AED6" Offset="0.75"/>
< GradientStop Color="#FF0B3EFF" Offset="1"/>
< /LinearGradientBrush>
< /Window.Resources>

Here's how to use it in WPF 3.5 SP1:
< Canvas x:Name="uxcLayoutRoot" Background="{DynamicResource LightBlue4Background}">
< TextBox x:Name="uxtDid" Background="{DynamicResource LightBlue4Background}"/>
< /Canvas>

I notice the difference in StaticResource vs DynamicResource.
Checking back, it doesn't seem to make a difference in WPF.

Dan

No comments:

Post a Comment