Hi all. I am writing a function to recurse my XAML and add all the controls to a hashtable, with their names being the keys. Unfortunately it seems like I have to go through and list every possible type:
void Recurse_Controls(object start)
{
string start_type = start.GetType().ToString();
if (start_type == "StackPanel")
{
ControlsByName.Add(((StackPanel)start).Name, start);
foreach (object item in ((StackPanel)start).Children)
{
Recurse_Controls(item);
}
}
if (start_type == "Grid")
{
ControlsByName.Add(((Grid)start).Name, start);
foreach (object item in ((Grid)start).Children)
{
Recurse_Controls(item);
}
}
}
Is there a simpler way of doing this?