ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/Utils/Wpf/TreeHelper.cs
/// <summary>
/// This will search for a parent of the specified type.
/// </summary>
/// <typeparam name="T">The type of the element to find</typeparam>
/// <param name="startingObject">The node where the search begins.</param>
/// <param name="checkStartingObject">Should the specified startingObject be checked first.</param>
/// <param name="additionalCheck">Provide a callback to check additional properties 
/// of the found elements. Can be left Null if no additional criteria are needed.</param>
/// <param name="scope">Should not search behond this parent. Scope value is excluded from the search</param>
/// <returns>Returns the found element. Null if nothing is found.</returns>
/// <example>Button button = TreeHelper.FindParent&lt;Button&gt;( this, foundChild => foundChild.Focusable );</example>
This will search for a parent of the specified type.
This will search for a parent of the specified type .
internal static T FindParent<T>( DependencyObject startingObject, bool checkStartingObject, Func<T, bool> additionalCheck, DependencyObject scope ) where T : DependencyObject
    {
      T foundElement;
      DependencyObject parent = ( checkStartingObject ? startingObject : TreeHelper.GetParent( startingObject, true ) );
      while( parent != null )
      {
        foundElement = parent as T;
        if( foundElement != null )
        {
          if( additionalCheck == null )
          {
            return foundElement;
          }
          else
          {
            if( additionalCheck( foundElement ) )
              return foundElement;
          }
        }
        parent = TreeHelper.GetParent( parent, true );
        if( object.ReferenceEquals( parent, scope ) )
          break;
      }
      return null;
    }
internal static T FindParent < T > ( DependencyObject startingObject , bool checkStartingObject , Func < T , bool > additionalCheck , DependencyObject scope ) where T : DependencyObject { T foundElement ; DependencyObject parent = ( checkStartingObject ? startingObject : TreeHelper . GetParent ( startingObject , true ) ) ; while ( parent != null ) { foundElement = parent as T ; if ( foundElement != null ) { if ( additionalCheck == null ) { return foundElement ; } else { if ( additionalCheck ( foundElement ) ) return foundElement ; } } parent = TreeHelper . GetParent ( parent , true ) ; if ( object . ReferenceEquals ( parent , scope ) ) break ; } return null ; }
This will search for a parent of the specified type.
This will search for a parent of the specified type .
Returns the found element. Null if nothing is found.
Returns the found element . Null if nothing is found .
startingObject
DependencyObject
The node where the search begins.
The node where the search begins .
checkStartingObject
bool
Should the specified startingObject be checked first.
Should the specified startingObject be checked first .
additionalCheck
Func<T, bool>
Provide a callback to check additional properties
of the found elements. Can be left Null if no additional criteria are needed.
Provide a callback to check additional properties of the found elements . Can be left Null if no additional criteria are needed .
scope
DependencyObject
Should not search behond this parent. Scope value is excluded from the search
Should not search behond this parent . Scope value is excluded from the search
typeparam
The type of the element to find
The type of the element to find
example
Button button = TreeHelper.FindParent( this, foundChild => foundChild.Focusable ).
Button button = TreeHelper . FindParent ( this foundChild = > foundChild . Focusable ) .