"Specified element is already the logical child of another element. Disconnect if first."
The error was due to, at the first time population of stack panel went happily
downloadStackPanel.Children.Add(videoDownloadStatus);
but at the second time when I tried to populate the global content to the stack panel, the previous instance of stack panel still holds the global content and prevented me to populate the same content further and caused an exception.
I tried lot many workarounds for populating the stack panel the second time and later found the solution to be too simple.
In Page_1.xaml I created Closing = "Window_Closing" event. This event will be fired when the current window is closed. In this event I cleared the stack panel
downloadStackPanel.Children.Clear()
so no more global content will be there before I go to new window(Page_2.xaml). Now if I go back to the Page_1.xaml the population of stack panel will happen with no exception as the contents are already cleared.
3 comments:
i didnt ynderstand the concept. Explain bit more.
In WPF, once a global data is added in the Stack Panel control, that controls value is maintained even after we navigate to other pages. This post is how I cleared that.
That's good nivas, is that clear needs to be done only in that event or can we call this clear first and then add the child controls again ??.... juz a doubt :)
Post a Comment