c# - WPF Close all child window except active child window and main window -


i have c# winforms code follows close child forms when open new child form:

private void closeallactiveforms(form[] mdichildren)         {             form[] childarray = mdichildren;             foreach (form childform in childarray)             {                 childform.close();             }         } 

how can use in wpf windows?

i tried below code, close windows including parent , active window.

private void closeallwindows()         {             (int intcounter = app.current.windows.count - 1; intcounter >= 0; intcounter--)             {                 application.current.windows[intcounter].close();             }         } 

thanks.

as far know, mdi support wpf limited, try using tag attribute when create pseudo-child windows:

window child = new window(); child.tag = "mdi_child"; 

then, in loop, modify this:

    foreach (window win in app.current.windows)     {         if (!win.isfocused && win.tag.tostring() == "mdi_child")         {             win.close();         }     } 

note above solution work, windows must have tag attribute, or else exception thrown @ "win.tag.tostring()"


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -