src/Foundation/Presentation/Gimela.Presentation.Controls/Controls/Timeline/Helpers/VisualTreeExtraHelper.cs
/// <summary>
/// Find a parent object of type parentItem in the visual tree, also searches logical tree at any level missing a visual parent.
/// </summary>
/// <remarks>
/// This could be made even more extensive to search both visual and logical and not look only for dependency objects in logical
/// tree, but that is for another day, since this fixed my current bug.
/// </remarks>
/// <typeparam name="TParentType"></typeparam>
/// <param name="outerDepObj"></param>
/// <returns></returns>
Find a parent object of type parentItem in the visual tree, also searches logical tree at any level missing a visual parent.
Find a parent object of type parentItem in the visual tree also searches logical tree at any level missing a visual parent .
public static TParentType FindVisualParentExtended<TParentType>(DependencyObject outerDepObj) where TParentType : DependencyObject
        {
            var visualParent = VisualTreeHelper.GetParent(outerDepObj);
            if (visualParent is TParentType) return visualParent as TParentType;
            if (visualParent == null)
            {
                var logicalParent = LogicalTreeHelper.GetParent(outerDepObj);
                if (logicalParent == null) return null;
                if (logicalParent is TParentType) return logicalParent as TParentType;
                visualParent = FindVisualParentExtended<TParentType>(logicalParent);
            }
            else
            {
                visualParent = FindVisualParentExtended<TParentType>(visualParent);
            }
            return visualParent as TParentType;
        }
public static TParentType FindVisualParentExtended < TParentType > ( DependencyObject outerDepObj ) where TParentType : DependencyObject { var visualParent = VisualTreeHelper . GetParent ( outerDepObj ) ; if ( visualParent is TParentType ) return visualParent as TParentType ; if ( visualParent == null ) { var logicalParent = LogicalTreeHelper . GetParent ( outerDepObj ) ; if ( logicalParent == null ) return null ; if ( logicalParent is TParentType ) return logicalParent as TParentType ; visualParent = FindVisualParentExtended < TParentType > ( logicalParent ) ; } else { visualParent = FindVisualParentExtended < TParentType > ( visualParent ) ; } return visualParent as TParentType ; }
Find a parent object of type parentItem in the visual tree, also searches logical tree at any level missing a visual parent.
Find a parent object of type parentItem in the visual tree also searches logical tree at any level missing a visual parent .
None
outerDepObj
DependencyObject
None
remarks
This could be made even more extensive to search both visual and logical and not look only for dependency objects in logical
tree, but that is for another day, since this fixed my current bug.
This could be made even more extensive to search both visual and logical and not look only for dependency objects in logical tree but that is for another day since this fixed my current bug .
typeparam
None