1 InvokeCommandAction ic = new InvokeCommandAction(); 2 ic.Command = tree.SelectedItemCommand;//绑定的命令 3 ic.CommandParameter = treeView; 4 System.Windows.Interactivity.EventTrigger et = new System.Windows.Interactivity.EventTrigger(); 5 et.EventName = "SelectedItemChanged"; 6 et.Actions.Add(ic); 7 System.Windows.Interactivity.TriggerCollection tc = Interaction.GetTriggers(treeView); 8 tc.Add(et);View Code
1 public static List<T> GetChildObj<T>(DependencyObject obj) where T : FrameworkElement 2 { 3 List<T> list = new List<T>(); 4 DependencyObject child = null; 5 for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(obj); i++) 6 { 7 child = System.Windows.Media.VisualTreeHelper.GetChild(obj, i); 8 if (child is T) 9 { 10 list.Add((T)child); 11 } 12 //GetChildObj<T>(child);//仅仅遍历只在当前控件内的元素 13 list.AddRange(GetChildObj<T>(child));//遍历当前控件包括所有子控件 14 } 15 16 return list; 17 }View Code
转载于:https://www.cnblogs.com/leeice/p/5736163.html