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

时间:2022-05-24 12:11:43
             InvokeCommandAction ic = new InvokeCommandAction();
ic.Command = tree.SelectedItemCommand;//绑定的命令
ic.CommandParameter = treeView;
System.Windows.Interactivity.EventTrigger et = new System.Windows.Interactivity.EventTrigger();
et.EventName = "SelectedItemChanged";
et.Actions.Add(ic);
System.Windows.Interactivity.TriggerCollection tc = Interaction.GetTriggers(treeView);
tc.Add(et);
         public static List<T> GetChildObj<T>(DependencyObject obj) where T : FrameworkElement
{
List<T> list = new List<T>();
DependencyObject child = null;
for (int i = ; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(obj); i++)
{
child = System.Windows.Media.VisualTreeHelper.GetChild(obj, i);
if (child is T)
{
list.Add((T)child);
}
//GetChildObj<T>(child);//仅仅遍历只在当前控件内的元素
list.AddRange(GetChildObj<T>(child));//遍历当前控件包括所有子控件
} return list;
}