Using TypeConverters with WPF
I'm working on a little project at the moment which is dynamically building a WPF user interface based on a configuration file loaded when the application starts. This involves code to manually create all of the bits and pieces that are normally specified directly in a Xaml file.
One useful shortcut I've found is to leverage .NETs built in TypeConverter framework - the same technique used by the Xaml loader itself.
For example, when creating a GridLength as part of setting up a Grid, the following shortcut works well:
var definition = // string definition for row height var converter = TypeDescriptor.GetConverter(typeof(GridLength)); var length = (GridLength)converter.ConvertFromString(definition);
The TypeDescriptor system provides access to a heap of useful capabilities that we've only just touched upon here. Worth following up.

Recent comments
4 weeks 15 hours ago
4 weeks 21 hours ago
4 weeks 1 day ago
4 weeks 1 day ago
8 weeks 1 day ago
9 weeks 16 hours ago
9 weeks 4 days ago
9 weeks 4 days ago
11 weeks 5 days ago
12 weeks 3 hours ago