Access object methods contained in a stackpanel.Children

0

Suppose that I put in StackPanel 5 objects of the class ConfigNivel , I would like later to access the methods of these 5 objects, for example, the method GetTotal() , which are housed inside ConfigNivel().GetTotal()

     private void ConstruirFilas(int numFilas)
     {

        for (int i = 1; i < numFilas; i++)
        {
            StackConfiguracion.Children.Add(new ConfigNivel(i));              
        }
     }

How can I access these?

    
asked by Edulon 08.01.2018 в 22:25
source

1 answer

1

Taking into account that the ConfigNivel elements can be housed in a StackPanel (derived from UIElement) to access them, it occurs to me that you could do it in the following way:

for (int i = 0; i < StackConfiguration.Children.Count; i++)
{
    total += (StackConfiguracion.Children[i] as ConfigNivel).GetTotal();              
}

This works as long as the class% co_of% is null. If not, you should do it like this:

for (int i = 0; i < StackConfiguration.Children.Count; i++)
{
    total += ((ConfigNivel)StackConfiguracion.Children[i]).GetTotal();              
}

ConfigNivel would be a variable of the same type that returns the total method, which I used as an example, but you could access properties and methods of the corresponding GetTotal() object in this way.

Greetings.

    
answered by 08.01.2018 / 22:58
source