CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2009
    Posts
    19

    Stopping a Window from loading twice.

    Hi.

    I have a menu item that loads a Window. The problem is every time I click the menu item it loads a new instance of the same Window. This may corrupt my database so I need only one Window open.

    I had a fix for this in Windows Forms but since WPF Windows do not implement IDisposable it does not work.

    Here is my Windows Forms code. How do I do this with WPF?

    Code:
    Class
    private FormAssociates  frmAssoc = null;
    
    MenuItem Handler
    If ((frmAssoc == null) || (frmAssoc.IsDisposed())
    {
    frmAssoc = new FormAssociates();
    frmAssoc.Owner = this;
    frmAssoc.Show();
    }
    else
    {
    // cannot bring a form to front if it is minimized...
    frmAssoc.WindowState = WindowState.Normal;
    frmAssoc.BringToFront();
    }

  2. #2
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Stopping a Window from loading twice.

    Just wondering... What stops you from simply using a boolean status variable for keeping track of the window's state - instead of testing IsDisposed()?

  3. #3
    Join Date
    Apr 2009
    Posts
    19

    Re: Stopping a Window from loading twice.

    Quote Originally Posted by gstercken View Post
    Just wondering... What stops you from simply using a boolean status variable for keeping track of the window's state - instead of testing IsDisposed()?
    Well for one I thought about that but then I would have very messy code because I would need a status bool for every window.

    Second, it doesn't work anyway because when Window1 loads Window2 with the Show() method there is no way to know that Window2 has been closed. Unlike ShowDialog() Window1 is not notified when Wndow2 calls its Close() method.

    I would have to do it manually with public global variables that work between Windows and its too messy.

    If you know of a way to do it with bool please show me the code.
    Last edited by Tealc; April 23rd, 2009 at 11:04 AM.

  4. #4
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Stopping a Window from loading twice.

    Quote Originally Posted by Tealc View Post
    Second, it doesn't work anyway because when Window1 loads Window2 with the Show() method there is no way to know that Window2 has been closed. Unlike ShowDialog() Window1 is not notified when Wndow2 calls its Close() method.
    Hm... But I still don't understand why you wouldn't simply handle the window's Closed event? That way, you can easily keep track of any window's state.

  5. #5
    Join Date
    Apr 2009
    Posts
    19

    Re: Stopping a Window from loading twice.

    Idk how to do that. I think I might just go back to Windows Forms it seems like WPF has a very long way to go yet. Designing a window is 10x harded then designing a form and I've found more little bugs in WPF then I care to comment about.

    Almost all of the usefull Form controls like DataGridView and several others that I use are missing from WPF and the ones like ListView that are included are severly limited in how they can be customized.

    I think I will try again when WPF has had time to mature.

  6. #6
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Thumbs up Re: Stopping a Window from loading twice.

    Quote Originally Posted by Tealc View Post
    Idk how to do that. I think I might just go back to Windows Forms it seems like WPF has a very long way to go yet. Designing a window is 10x harded then designing a form and I've found more little bugs in WPF then I care to comment about.

    Almost all of the usefull Form controls like DataGridView and several others that I use are missing from WPF and the ones like ListView that are included are severly limited in how they can be customized.

    I think I will try again when WPF has had time to mature.

    You are facing problems because you are new to WPF, once you attain a confort level, you would love to code in WPF. It has awesome features and is very powerful. I am also new to this environment and struggling to achieve what i could easily do in Winforms.

    So, all the best and happy coding

  7. #7
    Join Date
    Apr 2009
    Posts
    19

    Re: Stopping a Window from loading twice.

    Yes I am new and that probably is the cause of some of it but I'm also not stupid. I've been writing sofrware for years and WPF has so many bugs I'm suprised it was even released. It is so limited it so many ways its funny.

    1. There is no version of DataGridView that can be easily used.

    2. Many of the avaliable controls cannot be customized in a similar way that Windows Forms version can.

    3. There is no easy way to even get the ProductVersion. Application.ProductVersion has been removed. I mean seriously, common.

    4. The designer is completely messed up controls on the designer don't appear the same at runtime. I placed several labels on the window and alligned them. I ran the program and they were completely strewn all over the window in random places at runtime. To fix it I had to use the designer and resize the window just a tad and then the screen flashed and went black. After a few seconds it came back. I ran the program and every aligned correctly.

    Many times I moved controls around on the designer and at runtime the changes were not reflected. I had to completely close the IDE and restart it. I ran the program again and the changes were magically reflected correctly now.

    I could go on but I don't have time right now. I'm just not too impressed. Why should they expect people to migrate from powerfull and customizable Windows Forms to something lacking in every area and buggier then hell? I don't know.

  8. #8
    Join Date
    Apr 2009
    Location
    Bahamas
    Posts
    33

    Re: Stopping a Window from loading twice.

    WRONG.

    Sorry but you are completely wrong. There is nothing wrong with WPF. It has a few bugs but nothing like what you are saying.

    If you get this many issues you probably need to do a clean install of Visual Studio.

    MS is working on a DataGridView control its just not ready yet. For now you can use any of the Windows Forms controls you need by using the Host control. Until the WPF versions are finished.

    Designing a WPF window is different then Forms. Make sure you are correctly using the tools like Grid and Dock Panel, etc...

    I wrote the software that runs my businesses and am having a lot of fun redesigning the UI portion with WPF I have a slick seemless UI in the works that Forms could have never done. My software is huge and pushing WPF to the limits. Still I have yet to run into a issue as you are describing.
    Thanks,
    - pgrammer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured