WPF 按名称查找控件

1FrameworkElement类FindName方法

使用过程

1.容器控件.RegisterName("Name",要注册的控件)   //注册控件

2.容器控件.FindName("Name") as  控件类型            //找到控件并转换成相应类型

 注意:仅通过 控件.Name来设置是不能通过FindName来找到控件的,必须注册 

有添加就有删除。删除控件操作

1.容器控件.Children.Remove(控件) //移除控件

2.容器控件.UnregisterName("Name") //取消注册

2 VisualTreeHelper

 通过VisualTreeHelper的GetChildrenCount和GetChild方法来查找对象的子控件,GetParent方法查找对象的父级。

GetParent方法查找对象的父级。

 GetChildrenCount和GetChild方法来查找对象的子控件

原文地址:https://www.cnblogs.com/xinyf/p/10008089.html