Dan*_*ett 5 c# linq children uielementcollection
我有UniformGrid
一些Button
像Children
.每个Button
都有一个Tag
ID,例如(dumbed down代码):
MyUniformGrid.Children.Add(new Button {
Margin = new Thickness(5),
Tag = Query.GetUInt32("id"),
Width = 200
});
Run Code Online (Sandbox Code Playgroud)
如何选择Button
ID为87 的子对象?(例如)
当我输入MyUniformGrid.Children.
(添加后using System.Linq;
)时,Intellisense没有弹出Linq方法.
Dan*_*ett 10
干得好:
var MyButton = MyUniformGrid.Children.
OfType<Button>().
Single(Child => Child.Tag != null && Child.Tag == 87);
Run Code Online (Sandbox Code Playgroud)
LINQ不能直接运行MyUniformGrid.Children
,因为UIElementCollection
工具IEnumerable
,不是IEnumerable<T>
.因此OfType<Button>
是必需的.
归档时间: |
|
查看次数: |
2136 次 |
最近记录: |