private IDictionary CurrentDictionary (XamlElement element)
{
IDictionary rd = null;
XamlObjectElement obj = null;
if (element == null || element.Parent == null)
return null;
XamlPropertyElement prop = element.Parent as XamlPropertyElement;
if (prop == null) {
//
// We could be in a <ResourceDictionary> tag, so we get added via ContentProperty
//
obj = element.Parent as XamlObjectElement;
rd = obj.Object as IDictionary;
if (rd != null)
return rd;
return null;
}
//
// We aren't even in a <Something.Resources> element
//
if (!(typeof (IDictionary).IsAssignableFrom (prop.Type)))
return null;
//
// We need to be in a resource dictionary element, and we need that element to have a
// valid parent container.
//
obj = prop.Parent as XamlObjectElement;
if (obj == null)
return null;
FrameworkElement fe = obj.Object as FrameworkElement;
rd = fe.Resources;
return rd;
}