Prev | Current Page 121 | Next

Matthew MacDonald

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

The Brush class (and its derivatives) use the
BrushConverter because the Brush class is decorated with the TypeConverter(Get-
Type(BrushConverter)) attribute declaration.
If there??™s no associated type converter on the property declaration or the class declaration,
the XAML parser generates an error.
This system is simple but flexible. If you set a type converter at the class level, that converter
applies to every property that uses that class. On the other hand, if you want to
fine-tune the way type conversion works for a particular property, you can use the
TypeConverter attribute on the property declaration instead.
It??™s technically possible to use type converters in code, but the syntax is a bit convoluted.
It??™s almost always better to set a property directly??”not only is it faster, it also avoids potential
errors from mistyping strings, which won??™t be caught until runtime. (This problem doesn??™t
affect XAML, because the XAML is parsed and validated at compile time.) Of course, before
you can set the properties on a WPF element, you need to know a bit more about the basic
WPF properties and data types??”a job you??™ll tackle in the next few chapters.
nNote XAML, like all XML-based languages, is case-sensitive. That means you can??™t substitute