File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
Microsoft.Toolkit.Uwp.UI/Extensions/Tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -566,13 +566,24 @@ public static IEnumerable<FrameworkElement> FindParents(this FrameworkElement el
566
566
/// <returns>The retrieved content control, or <see langword="null"/> if not available.</returns>
567
567
public static UIElement ? TryGetContentControl ( this FrameworkElement element )
568
568
{
569
- Type type = element . GetType ( ) ;
569
+ Type ? type = element . GetType ( ) ;
570
570
571
- if ( type . GetCustomAttribute < ContentPropertyAttribute > ( true ) is ContentPropertyAttribute attribute &&
572
- type . GetProperty ( attribute . Name ) is PropertyInfo propertyInfo &&
573
- propertyInfo . GetValue ( element ) is UIElement content )
571
+ while ( type is not null )
574
572
{
575
- return content ;
573
+ // We need to manually explore the custom attributes this way as the target one
574
+ // one is not returned by any of the other available GetCustomAttribute<T> APIs.
575
+ foreach ( CustomAttributeData attribute in type . CustomAttributes )
576
+ {
577
+ if ( attribute . AttributeType == typeof ( ContentPropertyAttribute ) )
578
+ {
579
+ string propertyName = ( string ) attribute . NamedArguments [ 0 ] . TypedValue . Value ;
580
+ PropertyInfo propertyInfo = type . GetProperty ( propertyName ) ;
581
+
582
+ return propertyInfo . GetValue ( element ) as UIElement ;
583
+ }
584
+ }
585
+
586
+ type = type . BaseType ;
576
587
}
577
588
578
589
return null ;
You can’t perform that action at this time.
0 commit comments