我有一个UniformGrid
,Button
个Children
为Button
。每个Tag
都有MyUniformGrid.Children.Add(new Button {
Margin = new Thickness(5),
Tag = Query.GetUInt32("id"),
Width = 200
});
个ID,例如(愚蠢的代码):
Button
如何选择ID为87的子MyUniformGrid.Children.
对象? (例如)
当我输入using System.Linq;
时(在添加{{1}}之后),Linq方法没有弹出Intellisense。
答案 0 :(得分:10)
你走了:
var MyButton = MyUniformGrid.Children.
OfType<Button>().
Single(Child => Child.Tag != null && Child.Tag == 87);
自UIElementCollection
implements IEnumerable
, not IEnumerable<T>
以来,Linq无法直接在MyUniformGrid.Children
上投放。因此,OfType<Button>
是必需的。