Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Problem with multiple windows in WPF

Problem with multiple windows in WPF

Scheduled Pinned Locked Moved WPF
helpwpfcsharphtml
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gretna
    wrote on last edited by
    #1

    Hi its been a while since I've had a problem, but this has stumped me. I have a start-up screen which has three button on it and one of these opens another WPF window. I would like the window that opens to be able to be closed and re-opened if the button on the start screen is pressed again. However it seems to be crashing and the error I get is: Cannot convert the value in attribute 'Content' to object of type 'System.Object'. Specified element is already the logical child of another element. Disconnect it first. Error at object 'System.Windows.Controls.ContentControl' in markup file 'VisualEditor;component/designer.xaml' Line 28 Position 46. Any help is much appreciated. Gretna

    Some people are like slinky's... They're not really good for anything but they bring a smile to your face when pushed down the stairs

    D 1 Reply Last reply
    0
    • G Gretna

      Hi its been a while since I've had a problem, but this has stumped me. I have a start-up screen which has three button on it and one of these opens another WPF window. I would like the window that opens to be able to be closed and re-opened if the button on the start screen is pressed again. However it seems to be crashing and the error I get is: Cannot convert the value in attribute 'Content' to object of type 'System.Object'. Specified element is already the logical child of another element. Disconnect it first. Error at object 'System.Windows.Controls.ContentControl' in markup file 'VisualEditor;component/designer.xaml' Line 28 Position 46. Any help is much appreciated. Gretna

      Some people are like slinky's... They're not really good for anything but they bring a smile to your face when pushed down the stairs

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      Hy, Since you haven't shown any code or Xaml that you have, based on the error message, I would say/guess that your designer.xaml markup holds a reference to the sencond window(or a CONTROL in it) that you are trying to open/close. this really silly code inside window1/mainwindow works just fine:

          private Window2 w2 =null;
      
          private void button1\_Click(object sender, RoutedEventArgs e)
          {
              if (w2 == null)
              {
                  w2 = new Window2();
                  w2.Show();
              }
              else
              {
                  w2.Close();
                  w2 = null;
              }
              e.Handled=true;
          }
      
      G 1 Reply Last reply
      0
      • D Dan Mos

        Hy, Since you haven't shown any code or Xaml that you have, based on the error message, I would say/guess that your designer.xaml markup holds a reference to the sencond window(or a CONTROL in it) that you are trying to open/close. this really silly code inside window1/mainwindow works just fine:

            private Window2 w2 =null;
        
            private void button1\_Click(object sender, RoutedEventArgs e)
            {
                if (w2 == null)
                {
                    w2 = new Window2();
                    w2.Show();
                }
                else
                {
                    w2.Close();
                    w2 = null;
                }
                e.Handled=true;
            }
        
        G Offline
        G Offline
        Gretna
        wrote on last edited by
        #3

        Cheers for your reply. It didn't seem to work still but I have had an epiphany and manage to solve it thanks again for the help. It was because the content of some of my items on my second form was using static resource so on close of the second window I set the content to null. Gretna.

        Some people are like slinky's... They're not really good for anything but they bring a smile to your face when pushed down the stairs

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups