我有一个UniformGrid
与一些Button
's as Children
. Each Button
has a Tag
带有 ID,例如(简化代码):
MyUniformGrid.Children.Add(new Button {
Margin = new Thickness(5),
Tag = Query.GetUInt32("id"),
Width = 200
});
我该如何选择孩子Button
ID 为 87 的对象? (作为一个例子)
当我键入时,Intellisense 不会随 Linq 方法一起弹出MyUniformGrid.Children.
(添加后using System.Linq;
).
干得好:
var MyButton = MyUniformGrid.Children.
OfType<Button>().
Single(Child => Child.Tag != null && Child.Tag == 87);
Linq不能直接运行MyUniformGrid.Children
since UIElementCollection实施IEnumerable, not IEnumerable<T>。所以OfType<Button>
是必须的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)