Prev | Current Page 124 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

GradientStops>
CHAPTER 2 n XAML 35






...

nNote You can use property-element syntax for any property. But usually you??™ll use the simpler propertyattribute
approach if the property has a suitable type converter. Doing so results in more compact code.
Any set of XAML tags can be replaced with a set of code statements that performs the
same task. The tags shown previously, which fill the background with a gradient of your
choice, are equivalent to the following code:
Dim brush As New LinearGradientBrush()
Dim gradientStop1 As New GradientStop()
gradientStop1.Offset = 0
gradientStop1.Color = Colors.Red
brush.GradientStops.Add(gradientStop1)
Dim gradientStop2 As New GradientStop()
gradientStop2.Offset = 0.5
gradientStop2.Color = Colors.Indigo
brush.GradientStops.Add(gradientStop2)
Dim gradientStop3 As New GradientStop()
gradientStop3.Offset = 1
gradientStop3.Color = Colors.Violet
brush.GradientStops.Add(gradientStop3)
grid1.Background = brush
Markup Extensions
For most properties, the XAML property syntax works perfectly well. But in some cases, it just
isn??™t possible to hard-code the property value.


Pages:
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136