标签:null txt checkbox mit content amp enter val code
private void GetCheckBoxVal() { if (treeView != null) { ContentPresenter myContentPresenter = null; DataTemplate myDataTemplate = null; CheckBox ck = null; TextBlock tb = null; foreach (var item in treeView.Items) { DependencyObject obj = treeView.ItemContainerGenerator.ContainerFromItem(item); ; myContentPresenter = FindVisualChild<ContentPresenter>(obj); myDataTemplate = myContentPresenter.ContentTemplate; ck = (CheckBox)myDataTemplate.FindName("ck", myContentPresenter) as CheckBox; tb = (TextBlock)myDataTemplate.FindName("txt", myContentPresenter) as TextBlock; } } } private childItem FindVisualChild<childItem>(DependencyObject obj) where childItem : DependencyObject { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) { DependencyObject child = VisualTreeHelper.GetChild(obj, i); if (child != null && child is childItem) return (childItem)child; else { childItem childOfChild = FindVisualChild<childItem>(child); if (childOfChild != null) return childOfChild; } } return null; }
标签:null txt checkbox mit content amp enter val code
原文地址:https://www.cnblogs.com/yuanchao/p/11597020.html