Custom Type Converters

You cannot create your own type converters, unless you’re working in the context of WPF/Silverlight on the desktop. WPF exposes type converters as classes deriving from TypeConverter (BrushConverter, ColorConverter, and so on). To write your own, you create your own TypeConverter subclass. However, your type converter can only be used on properties marked with a TypeConverterAttribute custom attribute that points to your TypeConverter subclass. Or, if the source type you’re converting is one you created, you can mark that type with TypeConverterAttribute so it automatically applies to all properties of that type. The WPF XAML parser looks in both places to find the converter that it needs to invoke.

For example, the BrushConverter ...

Get XAML Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.