I'm trying to create a card game in WPF and I get the error: Specified Visual is already a child of another Visual or the root of a CompositionTarget. I have a window with a listview in it (named: handListview). The listview's itemssource is set to an
ObservableCollection<System.Windows.Controls.Image>
called _hand.
As I hover an image, it shows an enlargement of hovered image by having a mousemove event add the hovered image source to an Image control (called LargeCardPreview) .source, next to the play canvas..
When I double click an image, I'd have it removed from _hand and added as a child element to the play canvas called playCanvas. (I use playCanvas.Children.Add).
Here's where the problem comes in, when I double click the image, I remove the card from the _hand collection (which at first thought would disconnect the element from the HandListView since it was bound to the collection), and triggers a "OnCardPlayed" event. In this even I add the card to playCanvas.Children collection. But then I get the error.
I thought it might be because the LargeImagePreview was blocking it, so I set the source to Null. No change.
So I guess its because that even though I remove the card from the _hand observablecollection the image doesn't get disconnected immediately. So how do I force a disconnect?
Hope that my question is clear enough.