在WPF下可以通过名字在VirtualTree上获取。
从VirtualTree上通过名字获取控件的方法参考:
- public static T FindVisualChildByName<T>(Visual parent, string name) where T : Visual
- {
- if (parent != null)
- {
- for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
- {
- var child = VisualTreeHelper.GetChild(parent, i) as Visual;
- string controlName = child.GetValue(Control.NameProperty) as string;
- if (controlName == name)
- {
- return child as T;
- }
- else
- {
- T result = FindVisualChildByName<T>(child, name);
- if (result != null)
- return result;
- }
- }
- }
- return null;
- }
复制代码 |