Access objects created in another class, in what way?

2

I try to do the following ... In the main view MainWindow I generate as many objects ConfigNivel as I need, these objects are some views that will subsequently lodge other objects of the class ConfigNivel (other views with options within them) in which other objects will be created with properties that are changed through TextGroups . Could I somehow access all the properties of all the objects that I have created in the different views from the MainWindow?

 public partial class MainWindow : Window
    {
        private void ConstruirFilas(int numFilas)
        {

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



 public partial class ConfigNivel : UserControl
      {
          private void Click_Changed(object sender, EventArgs e)
          {
              spElemento.Children.Clear();
              switch (CB_SeleccionGrupo.SelectedIndex)
              {
                  case 0:
                      spElemento.Children.Add(new Grupos.cuPotencia());
                      break;
                  case 1:
                      spElemento.Children.Add(new Grupos.cuManiobra());
                      break;
                  case 2:
                      spElemento.Children.Add(new Grupos.cuPLC());
                      break;
                  case 3:
                      spElemento.Children.Add(new Grupos.cuBornero());
                      break;
              }            
           }
       }

With an equal image it is clearer, depending on the selections of ComboBox some objects or others are created. If it is not clear, I'll edit it.

    
asked by Edulon 10.01.2018 в 17:17
source

1 answer

1

Gbianchi's answer is the best for future understanding of what the application does. That said, finding objects of a specific type in a serious collection in the following way:

  var collecionConfigNivel =StackConfiguracion.Children.OfType<ConfigNivel>()

  foreach(var configNivel in result)
        {
            var colleccioncuPotencia = configNivel.spElemento.Children.OfType<Grupos.cuPotencia>();

            foreach (var cuPotencia in colleccioncuPotencia)
            {
                var propieddA = cuPotencia.propiedadA;
            }
        }

You can put it in a method and make it recursive if you know the common type of containers to go through all the children.

    
answered by 10.01.2018 в 19:35