Help with window array display (WPF template)

Asked

Viewed 76 times

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.'

You can notice that the exception is due to me being tried to open a window that opened and has already been closed.

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

  • To what exception do you refer? Without knowing the context in which this happens it will be difficult to know the reason..

  • I was more descriptive in the question.

  • Put the whole method.

  • I’ve been poking around the problem and I’ve been able to specify it better.

1 answer

0


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.