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字段不能从类型复选框中检索到。