FindVisualChild reference issue

Solution 1:

FindVisualChild method is not provided by WPF framework, you have to add them. May be you want this:

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);
            if (child != null && child is T)
            {
                yield return (T)child;
            }

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

public static childItem FindVisualChild<childItem>(DependencyObject obj)
    where childItem : DependencyObject
{
    foreach (childItem child in FindVisualChildren<childItem>(obj))
    {
        return child;
    }

    return null;
}

Add these methods in some utility class so they can be reuse.

Solution 2:

Also a common practice is to use these methods (posted by Rohit Vats) as extension methods, like this:

static class Utils
{

    public static IEnumerable<T> FindVisualChildren<T>(this DependencyObject depObj)
           where T : DependencyObject
    {
        ...
    }

    public static childItem FindVisualChild<childItem>(this DependencyObject obj)
        where childItem : DependencyObject
    {
        ...
    }

}

And then in your code:

using Utils;

class MyCode
{
    public static DataGridCellsPresenter GetPresenter(DataGridRow row)
    {
        return row.FindVisualChild<DataGridCellsPresenter>();
    }
}