Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想制作一个现有的数组,Brushes以便WPF我可以循环它们并在组合框中显示列表。我怎样才能做到这一点?
Brushes
WPF
我有这样的东西,但它不会工作,因为Brushes它不是一个数组。
string[] brushes = Brushes; foreach (string s in brushes) { comboBox.Items.Add(s); }
您可以使用反射。您可以使用匿名类型来保存名称和画笔。
var values = typeof (Brushes).GetProperties(). Select(p => new { Name = p.Name, Brush = p.GetValue(null) as Brush }). ToArray();
您只能通过以下方式访问名称:
var brushNames = values.Select(v => v.Name);