加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-13 20:09:25 所属栏目:百科 来源:网络整理
导读:我有一些 WPF控件.例如,TextBox.如何枚举该控件的所有依赖属性(如XAML编辑器那样)? public IListDependencyProperty GetAttachedProperties(DependencyObject obj){ ListDependencyProperty result = new ListDependencyProperty(); foreach (PropertyDescr
我有一些 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

(编辑:李大同)

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

    推荐文章
      热点阅读