How can I find WPF controls by name or type?

后端 未结 18 2943
庸人自扰
庸人自扰 2020-11-21 04:23

I need to search a WPF control hierarchy for controls that match a given name or type. How can I do this?

18条回答
  •  醉话见心
    2020-11-21 04:59

    My extensions to the code.

    • Added overloads to find one child by type, by type and criteria (predicate), find all children of type which meet the criteria
    • the FindChildren method is an iterator in addition to being an extension method for DependencyObject
    • FindChildren walks logical sub-trees also. See Josh Smith's post linked in the blog post.

    Source: https://code.google.com/p/gishu-util/source/browse/#git%2FWPF%2FUtilities

    Explanatory blog post : http://madcoderspeak.blogspot.com/2010/04/wpf-find-child-control-of-specific-type.html

提交回复
热议问题