如何枚举控件的所有依赖项属性? [英] How to enumerate all dependency properties of control?

查看:61
本文介绍了如何枚举控件的所有依赖项属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

这篇关于如何枚举控件的所有依赖项属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆