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
相關文章
相關標籤/搜索