using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows;

namespace ScrollingTwoGrids_Wpf_2009_Q12
{
	public static class FrameworkElementExtensions
	{
		public static FrameworkElement GetChildByName(this FrameworkElement parentVisual, string partName)
		{
			FrameworkElement result = null;

			result = (FrameworkElement)parentVisual.FindName(partName);
			if (result != null)
				return result;

			int childrenCount = VisualTreeHelper.GetChildrenCount(parentVisual);
			for (int i = 0; i < childrenCount; i++)
			{
				var child = VisualTreeHelper.GetChild(parentVisual, i) as FrameworkElement;
				if (child != null)
				{
					result = GetChildByName(child, partName);
					if (result != null)
						return result;
				}
			}
			return null;
		}
	}
}
