Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Silverlight中获取类型的依赖属性的最佳方法是什么_C#_.net_Silverlight_Reflection_Dependency Properties - Fatal编程技术网

C# 在Silverlight中获取类型的依赖属性的最佳方法是什么

C# 在Silverlight中获取类型的依赖属性的最佳方法是什么,c#,.net,silverlight,reflection,dependency-properties,C#,.net,Silverlight,Reflection,Dependency Properties,我想通过使用反射传递属性名来获取dependencProperty信息。我参考了许多论坛,这些论坛指导使用GetField方法 DependencyProperty dp = null; var fieldInfo = dependencyObjectType.GetField(dpName, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); if (fieldInfo != null) {

我想通过使用反射传递属性名来获取
dependencProperty
信息。我参考了许多论坛,这些论坛指导使用
GetField
方法

DependencyProperty dp = null;
var fieldInfo = dependencyObjectType.GetField(dpName, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
if (fieldInfo != null)
{
   dp = fieldInfo.GetValue(null) as DependencyProperty;
}
这可能不适用于所有控制类型。例如,如果选中复选框类型,则字段为空。那么在silverlight中获取DependencyProperty详细信息的正确方法是什么? 我的目标是,我尝试使用反射绑定控件。我想实现以下目标

Type controlType = Type.GetType("ControlName");
DependencyProperty dp = ?
FrameworkElement element = controlType as FramworkElement;
element.SetBinding(dp, new Binding("PropertyPath"));

在Silverlight 4和5中,哪个DependencyProperty字段不能从类型复选框中检索到。