如何从UIElementCollection中选择一个属性=某个值的子项?
我有一个UniformGrid
,有许多Button
作为Children
。 每个Button
都有一个带ID的Tag
,例如(dumbed down code):
MyUniformGrid.Children.Add(new Button { Margin = new Thickness(5), Tag = Query.GetUInt32("id"), Width = 200 });
如何选择ID为87的子Button
对象? (例如)
当我输入MyUniformGrid.Children.
时,Intellisense没有弹出Linq方法MyUniformGrid.Children.
(在using System.Linq;
添加之后using System.Linq;
)。
干得好:
var MyButton = MyUniformGrid.Children. OfType
Linq不能直接在MyUniformGrid.Children
上运行,因为UIElementCollection
实现了IEnumerable
,而不是IEnumerable
。 因此OfType
。