Created
September 21, 2016 13:00
-
-
Save mvacha/39ae973daf367ba4809a756b3e81f606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static T GetVisualChildByType<T>(this DependencyObject referenceVisual) where T : DependencyObject | |
{ | |
DependencyObject child = null; | |
for (Int32 i = 0; i < VisualTreeHelper.GetChildrenCount(referenceVisual); i++) | |
{ | |
child = VisualTreeHelper.GetChild(referenceVisual, i) as DependencyObject; | |
if (child != null && child is T) | |
{ | |
break; | |
} | |
else if (child != null) | |
{ | |
child = GetVisualChildByType<T>(child); | |
if (child != null && child is T) | |
{ | |
break; | |
} | |
} | |
} | |
return child as T; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment