I got a canvas on what I add some UIElements like this:
private void AddChild(UIElement child, Canvas parent)
// first I remove all the other children
// then I add the new one
I add my new field on this canvas like this:
private void AddField()
AddChild(new FieldView(), MainCanvas);
So I have no other reference to that FieldView, but on the canvas.
This FieldView listens to some events and shows some MessageBoxes. Now, when I add a new FieldView on the MainCanvas, the only reference of the old one should be removed (if I understand this parent.Children.Clear() right).
But it seems like it's not really collected by the GarbageCollector, because now, I always get 2 MessageBoxes on these events (if I add a new field again, I get 3 MessageBoxes and so on).
Can anyone of you tell me, why the old FieldViews aren't removed? Is it just because they still listen to those events or doesn't parent.Children.Clear() really remove them?
Thank you for your help!