Пример #1
0
 /// <summary>
 /// The collapse all button click.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void CollapseAllButtonClick(object sender, RoutedEventArgs e)
 {
     foreach (TreeViewItem node in VisualTreeHelperHelper.FindVisualChildren <TreeViewItem>(this.Folders))
     {
         node.IsExpanded = false;
     }
 }
Пример #2
0
        public static IEnumerable <T> FindVisualChildren <T>(DependencyObject depObj) where T : DependencyObject
        {
            if (depObj != null)
            {
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                {
                    DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
                    T item = child as T;
                    if (item != null)
                    {
                        yield return(item);
                    }

                    foreach (T childOfChild in VisualTreeHelperHelper.FindVisualChildren <T>(child))
                    {
                        yield return(childOfChild);
                    }
                }
            }
        }