wpf – 如何枚举控件的所有依赖属性?

前端之家收集整理的这篇文章主要介绍了wpf – 如何枚举控件的所有依赖属性?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些 WPF控件.例如,TextBox.如何枚举该控件的所有依赖属性(如XAML编辑器那样)?
  1. public IList<DependencyProperty> GetAttachedProperties(DependencyObject obj)
  2. {
  3. List<DependencyProperty> result = new List<DependencyProperty>();
  4.  
  5. foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(obj,new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.All) }))
  6. {
  7. DependencyPropertyDescriptor dpd =
  8. DependencyPropertyDescriptor.FromProperty(pd);
  9.  
  10. if (dpd != null)
  11. {
  12. result.Add(dpd.DependencyProperty);
  13. }
  14. }
  15.  
  16. return result;
  17. }

在这里找到:http://social.msdn.microsoft.com/Forums/en/wpf/thread/580234cb-e870-4af1-9a91-3e3ba118c89c

猜你在找的设计模式相关文章