This is annoying:
<GeometryDrawing>
<GeometryDrawing.Pen>
<Pen Brush="Black"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
I want this:
<GeometryDrawing Pen="Black"/>
So I write a TypeConverter
:
public class PenConverter : TypeConverter
{
static readonly BrushConverter brushConverter = new BrushConverter();
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string)) return true;
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var s = value as string;
if (a != null)
{
var brush = brushConverter.ConvertFromInvariantString(s) as Brush;
return new Pen(brush, 1);
}
return base.ConvertFrom(context, culture, value);
}
}
Now, how do I link it up with the Pen
type? I can't just add a TypeConverterAttribute
to it as I don't own it (nor do I own GeometryDrawing.Pen
property).