I have a 'loader app' that loads a menu and when user clicks the menu image button a list view opens based on the text
(if text = employee)
(Go to class A)
(Go to class B)
...
...
(Show List View Window)
if he clicks again on the same button it opens again, I would like to prevent this. i.e but this for a WPF application
Another simple example
Mark Garvell's answer helped me to figure out what I should do, but it needed adjusting for WPF.
(In my case I wanted to close any windows not owned by the main one when it closes, but the principle is the same.)
You can use a Command pattern. The loader assembly will search for commands in loaded assemblies. For every command the loader create menu item ( or anything else, you want ), and click event will run the concrete command.
The command must know if should be created new form or used some already existing.
If you want a list of the open forms, that is
Application.OpenForms
. You could iterate over this, using GetType() and checking the.Assembly
to find those from a different assembly. Beyond that, I'm not entire clear on the question...If you just want to track forms you have opened yourself, then cache that instance. Or if you use "owned forms", you can just check by name: