Help with window array display (WPF template)

0

Be the code snippet:

Janela[] jnl = new Janela[3];



for(int i = 0; i < jnl.Length; i++)//inicializa os objetos janelas

{

       jnl[i] = new Janela();

}

//Código que produz o layout de que cada janela vem aqui.


for(int i = 0; i < jnl.Length; i++ )//Deveria chamar as janelas uma a uma, mas....

{

jnl[i].ShowDialog();// ....aqui, em vez de chamar apenas a janela indicada pelo 
                   //indice i, são chamadas todas as janelas do array em uma 
                   //única chamada. Na próxima interação, após eu fechar todas 
                   //as janelas abertas, é lançada a excepção descrita abaixo.

}

The debugger message is as follows:

System.InvalidOperationException: 'Não será possível definir Visibility nem chamar Show, ShowDialog ou WindowInteropHelper.EnsureHandle depois que uma Janela for fechada.'

Note that the exception is due to the fact that I tried to open a window that opened and has already been closed.

The question is: why is the ShowDialog() method of all elements of the array called at once, but not just the index element i in every interaction with the jnl[i].ShowDialog(); statement?

    
asked by anonymous 07.04.2017 / 01:03

1 answer

0

This bug aberration turned out to be part of one of the Visual Studio processes. Step-by-step debugging does not lie: everything is done in just one execution line (opening windows without being explicitly referenced). I think it's in the debugging (insert code) part, because the compiler is right (I created a new project and the code ran !!!).

    
08.04.2017 / 06:54