private static Func <DependencyObject, bool> GetTemplatedChildExpandPredicate(IDataGridItemContainer source)
        {
            var fe = source as FrameworkElement;

            if (fe == null)
            {
                throw new ArgumentException("The source object must be a FrameworkElement.", "source");
            }

            return(( DependencyObject item ) => IDataGridItemContainerExtensions.ExpandChild(item) &&
                   IDataGridItemContainerExtensions.IsPartOfTargetTemplate(item, fe));
        }