Home > Software design >  Why does my function to only open one Window not work?
Why does my function to only open one Window not work?

Time:12-07

so I want in my Project to only open 1 instance of my Window. So I gave the Window a Title and tried to track every opening with that:

 foreach (Window window in Application.Current.Windows)
                {
                    if (window.Title == "QUALI-NET")
                    {
                        temp  ;
                    }

                }

and then i wanted to call my Function when this if statement is true:

 if (temp == 1)

I have build this 2 in an extra Class and have an Switch Case around this. Above the Switch Case I initiliaze this:

            QualiWindow WPFQuali = new QualiWindow(Mandant, Data.GetValue<string>("Artikelnummer"));

But The problem when I Open one Window and then open and another Window then it wont open but when I close the first started Window, I cant open the Window ever Again? I just want to allow one Instance of this Window to open. What am Im doing wrong?

I already tried the solutions from here: How can I make sure only one WPF Window is open at a time?

But none of that is working. Is there a Way to get every opened Window from taskbar or something and just allow one Window with that name XY. to open

CodePudding user response:

If you're keeping a count of the open windows with that title you also need to decrement the count whenever you close the window.

  • Related