WPF 界面控件遍历和后台行为绑定写法

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

 

posted @ 2016-08-04 11:57  LEE ICE  阅读(550)  评论(0编辑  收藏  举报