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

原文链接:http://www.cnblogs.com/leeice/p/5736163.html WPF 界面控件遍历和后台行为绑定写法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

 

WPF 界面控件遍历和后台行为绑定写法WPF 界面控件遍历和后台行为绑定写法
 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

上一篇:安卓APP_ 控件(3)—— EditText


下一篇:机器翻译中的强化学习:优点、缺点以及不足