|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using LinqToTree;
using System.Windows.Controls;
namespace LinqToTreeWPF
{
/// <summary>
/// An adapter for DependencyObject which implements ILinqToTree in
/// order to allow Linq queries on the visual tree
/// </summary>
public class VisualTreeAdapter : ILinqToTree<DependencyObject>
{
private DependencyObject _item;
public VisualTreeAdapter(DependencyObject item)
{
_item = item;
}
public IEnumerable<ILinqToTree<DependencyObject>> Children()
{
int childrenCount = VisualTreeHelper.GetChildrenCount(_item);
for (int i = 0; i < childrenCount; i++)
{
yield return new VisualTreeAdapter(VisualTreeHelper.GetChild(_item, i));
}
}
public ILinqToTree<DependencyObject> Parent
{
get
{
return new VisualTreeAdapter(VisualTreeHelper.GetParent(_item));
}
}
public DependencyObject Item
{
get
{
return _item;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.