C# 如何在Silverlight中获取DependencyProperty用于其值的类型?

C# 如何在Silverlight中获取DependencyProperty用于其值的类型?,c#,silverlight,dependency-properties,C#,Silverlight,Dependency Properties,我想检查DependencyProperty的类型,在WPF中,我可以执行以下操作: DependencyProperty property = ...; var typeAsString = property.PropertyType.Name; 因为属性类型在WPF中 我想知道是否有其他方法可以在Silverlight中实现这一点。我认为这可能值得您一看。 您必须使用反射: public static DependencyProperty GetDependencyProper

我想检查DependencyProperty的类型,在WPF中,我可以执行以下操作:

DependencyProperty property = ...;
var typeAsString = property.PropertyType.Name;
因为
属性类型
在WPF中


我想知道是否有其他方法可以在Silverlight中实现这一点。

我认为这可能值得您一看。

您必须使用反射:

     public static DependencyProperty GetDependencyProperty(Type type, string name)
 {
     FieldInfo fieldInfo = type.GetField(name, BindingFlags.Public | BindingFlags.Static);
     return (fieldInfo != null) ? (DependencyProperty)fieldInfo.GetValue(null) : null;
 }
从答案中可以看出,用法是:

 var dp = GetDependencyProperty(typeof(TextBox), "TextProperty");

HTH

感谢您的回复,不幸的是,我看到了这一点,它按预期工作,但不是为了我要实现的目标。它将从一个字符串中给我DP,我想要的是找到DP所代表的类型,这样我就可以创建一个“解析器”,为它设置一个来自持久性实现的值。