Windows Presentation Foundation introduces a number of new concepts, such as XAML, dependency properties, data binding (in the WPF/XAML world), and type converters. Let's take a brief look at type converters and how they're used in WPF.
Since XAML is an XML dialect, parameters to objects are specified as strings. The parameters aren't usually actually strings, so we need a way for the XAML parser to convert the string to the correct object type. This is accomplished via type converters.
Using a type converter is XAML is easy, for example:
<Button Content="Accept" Background="Blue" />
The color specified as a string is converted to a Color object by the XAML parser, since the Button class' Background property is of type Color.
A type converter is obtained by passing a type of object to the GetConverter method, like this:
System.ComponentModel.TypeDescriptor.GetConverter(typeof(type));
The TypeConverter class has a number of useful methods, some of which are:
One of the beautiful things about XAML and other bits introduced with WPF is that they aren't WPF specific. XAML is an application markup language that mirrors .NET classes in markup, so can be used outside WPF. Type converters are no different - the support is built into .NET 3.0+ so you can add knowledge of these bits to your tool kit and use them where appropriate.
If you want to implement your own type converter, reference this link at MSDN: http://msdn2.microsoft.com/en-us/library/ayybcxe5....
Powered by: newtelligence dasBlog 1.9.6264.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2009, Jeff Scanlon
E-mail