Find all controls in WPF Window by type

后端 未结 17 1296
春和景丽
春和景丽 2020-11-21 10:14

I\'m looking for a way to find all controls on Window by their type,

for example: find all TextBoxes, find all controls implementing specific i

17条回答
  •  故里飘歌
    2020-11-21 10:50

    Do note that using the VisualTreeHelper does only work on controls that derive from Visual or Visual3D. If you also need to inspect other elements (e.g. TextBlock, FlowDocument etc.), using VisualTreeHelper will throw an exception.

    Here's an alternative that falls back to the logical tree if necessary:

    http://www.hardcodet.net/2009/06/finding-elements-in-wpf-tree-both-ways

提交回复
热议问题