0
컨트롤의 모든 종속성 속성을 가져오고 싶습니다. 또한 유사한 유래 question리플렉션을 사용하여 uwp의 종속성 속성을 가져올 수 없습니다.
static IEnumerable<FieldInfo> GetDependencyProperties(this Type type)
{
var dependencyProperties = type.GetFields(BindingFlags.Static | BindingFlags.Public)
.Where(p => p.FieldType.Equals(typeof(DependencyProperty)));
return dependencyProperties;
}
public static IEnumerable<BindingExpression> GetBindingExpressions(this FrameworkElement element)
{
IEnumerable<FieldInfo> infos = element.GetType().GetDependencyProperties();
foreach (FieldInfo field in infos)
{
if (field.FieldType == typeof(DependencyProperty))
{
DependencyProperty dp = (DependencyProperty)field.GetValue(null);
BindingExpression ex = element.GetBindingExpression(dp);
if (ex != null)
{
yield return ex;
System.Diagnostics.Debug.WriteLine("Binding found with path: “ +ex.ParentBinding.Path.Path");
}
}
}
}
: 내가 좋아하는 뭔가를 시도했다. GetFields
메서드는 항상 빈 열거 형을 반환합니다.
[편집] 난 보편적 인 윈도우 플랫폼 프로젝트
typeof(CheckBox).GetFields() {System.Reflection.FieldInfo[0]}
typeof(CheckBox).GetProperties() {System.Reflection.PropertyInfo[98]}
typeof(CheckBox).GetMembers() {System.Reflection.MemberInfo[447]}
에서 다음 라인은 버그가 보인다 실행?
GetFields는 나를 위해 작동하지만 물론 기본 클래스가 아닌'type'에 선언 된 DependencyProperty 필드 만 반환합니다. 그 외에도'p.FieldType.Equals (typeof (DependencyProperty))'와'field.FieldType == typeof (DependencyProperty)'를 모두 사용하는 것은 의심 스럽습니다. 'typeof (DependencyProperty) .IsAssignableFrom (f.FieldType))'을 더 잘 작성하십시오. – Clemens
디버거에있을 때 typeof (ListBox) .GetFields()를 실행하면 빈 목록이 표시됩니다. – Briefkasten