<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpfApplication1="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid wpfApplication1:NewPropertyHelper.Prop="{Binding}">
</Grid>
</Window>
namespace WpfApplication1
{
public static class NewPropertyHelper
{
public static readonly DependencyProperty PropProperty = DependencyProperty.RegisterAttached("Prop", typeof (object), typeof (NewPropertyHelper), new PropertyMetadata(default(object)));
public static object GetProp(UIElement element)
{
return (object) element.GetValue(PropProperty);
}
public static void SetProp(UIElement element, object value)
{
element.SetValue(PropProperty, value);
}
}
}
public static IEnumerable<T> GetAllChildren<T>(this UIElement frameworkElement) where T : UIElement
{
if (frameworkElement == null)
{
yield break;
}
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(frameworkElement); i++)
{
var _Child = VisualTreeHelper.GetChild(frameworkElement, i);
if (_Child is T)
{
yield return (_Child as T);
}
var control = _Child as UIElement;
foreach (var child in GetAllChildren<T>(control))
{
yield return child;
}
}
}