Problem with multiple windows in WPF
-
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
-
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
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; }
-
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; }
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