How to enumerate all dependency properties of control?

前端 未结 5 1793
名媛妹妹
名媛妹妹 2020-12-01 21:17

I have some WPF control. For example, TextBox. How to enumerate all dependency properties of that control (like XAML editor does)?

5条回答
  •  爱一瞬间的悲伤
    2020-12-01 22:06

    If you want name of the DependencyProperties of an element then you can do this:

        var results = from prop in typeof(element).GetFields() 
                      where prop.FieldType == typeof(DependencyProperty)
                      select prop.Name.Substring(0, prop.Name.Length - 8);
    

    where 8 is length of the string "Property" which appears at the end of a dependency property!

提交回复
热议问题