Skip to content

Instantly share code, notes, and snippets.

@MwBakker
Last active April 15, 2020 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MwBakker/c7a256e09624866c1f9635ade18a0e88 to your computer and use it in GitHub Desktop.
Save MwBakker/c7a256e09624866c1f9635ade18a0e88 to your computer and use it in GitHub Desktop.
public IEnumerable<DependencyObject> ScanElementsOnMatch(IElementReference elementReference, DependencyObject viewToSearchIn)
{
string elementReferenceType = elementReference.Type.Description.ToLower();
int childrenCount = 0;
Application.Current.Dispatcher.Invoke(() => { childrenCount = VisualTreeHelper.GetChildrenCount(viewToSearchIn); });
for (var i = 0; i < childrenCount; i++)
{
DependencyObject child = null;
Application.Current.Dispatcher.Invoke(() => { child = VisualTreeHelper.GetChild(viewToSearchIn, i); });
foreach (DependencyObject meuk in ScanElementsOnMatch(elementReference, child))
{
yield return meuk;
}
}
yield return viewToSearchIn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment