Created
December 31, 2020 19:23
-
-
Save judismith/5b11c3d864bf446e770a70366d390e5a to your computer and use it in GitHub Desktop.
Xamarin : Get all the child controls of type<T> of a form by sending in the root control (ContentPage)
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
private static IList<T> GetAllControlsOfType<T>(Element view) where T : View | |
{ | |
var rtn = new List<T>(); | |
foreach (View item in view.Descendants()) | |
{ | |
var ctr = item as T; | |
if (ctr != null) | |
{ | |
rtn.Add(ctr); | |
} | |
else | |
{ | |
rtn.AddRange(GetAllControlsOfType<T>(item)); | |
} | |
} | |
return rtn; | |
} | |
//Hat Tip: https://stackoverflow.com/a/23214747/8205973 | |
// Example Usage: IList<SfTextInputLayout> inputs = GetAllControlsOfType<SfTextInputLayout>(SignUpForm); | |
// where "SignUpForm" is the x:Name property of the ContentPage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment