Csharp/C#教程:如何从UIElementCollection中选择一个属性=某个值的子项?分享


如何从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

上述就是C#学习教程:如何从UIElementCollection中选择一个属性=某个值的子项?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1013094.html

(0)
上一篇 2021年12月30日
下一篇 2021年12月30日

精彩推荐