locked
check open windows in wpf RRS feed

  • Question

  • hi

    i am using vs2010 c# wpf application.

    i have one code for windows application i.e when i pass windows form name , it check if already open then it will reactivate , if not open then it create new object and open it. the code as given below.

    but i am deveoping wpf application i want use this code but this code not working...

    any body know how to convert this code to wpf?

    public void NodeClick(string formName)
    {
    switch (formName)
    {
    case "frmPartMaster":
    if ((partMaster = (frmPartMaster)IsFormAlreadyOpen(typeof(frmPartMaster))) == null)
    {
    partMaster = new frmPartMaster();
    partMaster.Show(this);
    }
    else
    {
    partMaster.Activate();
    partMaster.WindowState = FormWindowState.Normal;
    partMaster.BringToFront();
    }
    break;
    }
    }
    public static Form IsFormAlreadyOpen(Type FormType)
    {
    foreach (Form OpenForm in System.Windows.Forms.Application.OpenForms)
    {
    if (OpenForm.GetType() == FormType)
    return OpenForm;
    }
    return null;
    }


    Best Regard Naweez

    • Moved by Mike Danes Wednesday, September 19, 2012 7:28 AM wpf specific (From:Visual C# General)
    Wednesday, September 19, 2012 6:55 AM

Answers

  • Hi naweez,

    You an use the below code in your IsFormAlreadyOpen function

            foreach(Window openWin in System.Windows.Application.Current.Windows)
             {
                     if (openWin.GetType() == winType)
                        return openWin;
             }
           Hope it helps

    Please let me know if you have any further query.

    Regards

    Ashish

    -------------------------------------------------------------------------

    If a reply answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by naweez Wednesday, September 19, 2012 10:58 AM
    Wednesday, September 19, 2012 10:32 AM

All replies

  • Hi naweez,

    You an use the below code in your IsFormAlreadyOpen function

            foreach(Window openWin in System.Windows.Application.Current.Windows)
             {
                     if (openWin.GetType() == winType)
                        return openWin;
             }
           Hope it helps

    Please let me know if you have any further query.

    Regards

    Ashish

    -------------------------------------------------------------------------

    If a reply answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by naweez Wednesday, September 19, 2012 10:58 AM
    Wednesday, September 19, 2012 10:32 AM
  • thanks for reply , it's working

    Best Regard Naweez

    Wednesday, September 19, 2012 10:58 AM