static DependencyProperty GetForegroundProperty(FrameworkElement element)
{
if (element is Control)
{
return(Control.ForegroundProperty);
}
if (element is TextBlock)
{
return(TextBlock.ForegroundProperty);
}
Type type = element.GetType();
DependencyProperty foregroundProperty;
if (!ForegroundProperties.Value.TryGetValue(type, out foregroundProperty))
{
FieldInfo field = ReflectionExtensions.GetFields(type).FirstOrDefault(f => f.Name == "ForegroundProperty");
if (field == null)
{
throw new ArgumentException("type is not a Foregroundable type");
}
var property = (DependencyProperty)field.GetValue(null);
ForegroundProperties.Value.TryAdd(type, property);
return(property);
}
return(foregroundProperty);
}