加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 程序设计 > 正文

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

发布时间:2020-05-23 11:24:50 所属栏目:程序设计 来源:互联网
导读:我有一些 WPF控件.例如,TextBox.如何枚举该控件的所有依赖属性(如XAML编辑器那样)? public IListDependencyProperty GetAttachedProperties(DependencyObject obj){ ListDependencyProperty result = new ListDependencyProperty();

我有一些 WPF控件.例如,TextBox.如何枚举该控件的所有依赖属性(如XAML编辑器那样)?

public IList<DependencyProperty> GetAttachedProperties(DependencyObject obj)
{
    List<DependencyProperty> result = new List<DependencyProperty>();

    foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(obj,new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.All) }))
    {
        DependencyPropertyDescriptor dpd =
            DependencyPropertyDescriptor.FromProperty(pd);

        if (dpd != null)
        {
            result.Add(dpd.DependencyProperty);
        }
    }

    return result;
}

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

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读