Wpf find all Controlles by tag and type

前端 未结 2 1087
夕颜
夕颜 2021-01-16 15:35

I\'m trying to retrieve of all elements by type and tag name. I already found some examples:

How can I find WPF controls by name or type?

https://stackoverfl

2条回答
  •  一向
    一向 (楼主)
    2021-01-16 16:08

    You could use the following FindVisualChildren method:

    Find all controls in WPF Window by type

    ...and simply filter the results:

    string tagName = "tagname";
    IEnumerable elements = FindVisualChildren(this).Where(x => x.Tag != null && x.Tag.ToString() == tagName);
    

提交回复
热议问题