Find all controls in WPF Window by type

后端 未结 17 1230
春和景丽
春和景丽 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:49

    I found it easier without Visual Tree Helpers:

    foreach (UIElement element in MainWindow.Children) {
        if (element is TextBox) { 
            if ((element as TextBox).Text != "")
            {
                //Do something
            }
        }
    };
    

提交回复
热议问题