gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 01:35:40 27 4
gpt4 key购买 nike

我有一些 WPF 控件。例如,文本框。如何枚举该控件的所有依赖属性(就像 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

关于wpf - 如何枚举控件的所有依赖属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4794071/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com