private static RoutedEvent ConvertRoutedEventArgs (XamlTypeConverter converter, ITypeDescriptorContext context, CultureInfo culture, object ovalue)
{
string value = (string) ovalue;
int dot = value.IndexOf (".");
if (dot < 1)
throw new XamlParseException ("Invalid format for RoutedEvent.");
string type_name = value.Substring (0, dot);
string event_name = value.Substring (dot + 1, value.Length - dot - 1);
Type type = converter.parser.LoadType (null, converter.parser.DefaultXmlns, type_name);
RoutedEvent res = null;
Type eventids = typeof (EventIds);
// Try UIElement first since thats where most of these events live
if (typeof (UIElement).IsAssignableFrom (type)) {
res = RoutedEvent (eventids, "UIElement", event_name);
if (res != null) {
Console.WriteLine ("returning routed event: {0}", res);
return res;
}
}
if (!type.IsValueType) {
Type walk = type;
while (walk != typeof (object)) {
res = RoutedEvent (eventids, walk.Name, event_name);
if (res != null)
return res;
walk = walk.BaseType;
}
}
return null;
}