@@ -715,110 +715,5 @@ public static bool TryFindResource(this FrameworkElement element, object resourc
715715 {
716716 return ( value = TryFindResource ( element , resourceKey ) ) is not null ;
717717 }
718-
719- /// <summary>
720- /// Find the first parent of type <see cref="FrameworkElement"/> with a given name.
721- /// </summary>
722- /// <param name="element">The starting element.</param>
723- /// <param name="name">The name of the element to look for.</param>
724- /// <param name="comparisonType">The comparison type to use to match <paramref name="name"/>.</param>
725- /// <returns>The parent that was found, or <see langword="null"/>.</returns>
726- public static FrameworkElement ? FindParent ( this FrameworkElement element , string name , StringComparison comparisonType = StringComparison . Ordinal )
727- {
728- return FindParent < FrameworkElement , ( string Name , StringComparison ComparisonType ) > (
729- element ,
730- ( name , comparisonType ) ,
731- static ( e , s ) => s . Name . Equals ( e . Name , s . ComparisonType ) ) ;
732- }
733-
734- /// <summary>
735- /// Find the first parent element of a given type.
736- /// </summary>
737- /// <typeparam name="T">The type of elements to match.</typeparam>
738- /// <param name="element">The starting element.</param>
739- /// <returns>The parent that was found, or <see langword="null"/>.</returns>
740- public static T ? FindParent < T > ( this FrameworkElement element )
741- where T : notnull , FrameworkElement
742- {
743- while ( true )
744- {
745- if ( element . Parent is not FrameworkElement parent )
746- {
747- return null ;
748- }
749-
750- if ( parent is T result )
751- {
752- return result ;
753- }
754-
755- element = parent ;
756- }
757- }
758-
759- /// <summary>
760- /// Find the first parent element of a given type.
761- /// </summary>
762- /// <param name="element">The starting element.</param>
763- /// <param name="type">The type of element to match.</param>
764- /// <returns>The parent that was found, or <see langword="null"/>.</returns>
765- public static FrameworkElement ? FindParent ( this FrameworkElement element , Type type )
766- {
767- return FindParent < FrameworkElement , Type > ( element , type , static ( e , t ) => e . GetType ( ) == t ) ;
768- }
769-
770- /// <summary>
771- /// Find the first parent element matching a given predicate.
772- /// </summary>
773- /// <typeparam name="T">The type of elements to match.</typeparam>
774- /// <param name="element">The starting element.</param>
775- /// <param name="predicate">The predicatee to use to match the parent nodes.</param>
776- /// <returns>The parent that was found, or <see langword="null"/>.</returns>
777- public static T ? FindParent < T > ( this FrameworkElement element , Func < T , bool > predicate )
778- where T : notnull , FrameworkElement
779- {
780- while ( true )
781- {
782- if ( element . Parent is not FrameworkElement parent )
783- {
784- return null ;
785- }
786-
787- if ( parent is T result && predicate ( result ) )
788- {
789- return result ;
790- }
791-
792- element = parent ;
793- }
794- }
795-
796- /// <summary>
797- /// Find the first parent element matching a given predicate.
798- /// </summary>
799- /// <typeparam name="T">The type of elements to match.</typeparam>
800- /// <typeparam name="TState">The type of state to use when matching nodes.</typeparam>
801- /// <param name="element">The starting element.</param>
802- /// <param name="state">The state to give as input to <paramref name="predicate"/>.</param>
803- /// <param name="predicate">The predicatee to use to match the parent nodes.</param>
804- /// <returns>The parent that was found, or <see langword="null"/>.</returns>
805- public static T ? FindParent < T , TState > ( this FrameworkElement element , TState state , Func < T , TState , bool > predicate )
806- where T : notnull , FrameworkElement
807- {
808- while ( true )
809- {
810- if ( element . Parent is not FrameworkElement parent )
811- {
812- return null ;
813- }
814-
815- if ( parent is T result && predicate ( result , state ) )
816- {
817- return result ;
818- }
819-
820- element = parent ;
821- }
822- }
823718 }
824719}
0 commit comments