Hi everyone,
I'm trying to implement the following: I have an Items Manager, that has an Item class inside. Item class can store two possible visual representations of it - BitmapImage(bitmap) and UserControl(vector).
Then later, in the game, I need to share the same image or vector control between all possible places it takes place. For example, consider 10 trees on the map, and all point to the same vector control. Or in some cases this can be bitmap image source.
So, the problem is that BitmapImage source can be easily shared in the application by multiple UIElements. However, when I try to share vector control, it fails, and says Child Element is already a Child element of another control. I want to know how to organize this in the best way. For example replace UserControl with other type of control, or storage, however I need to be sure it supports Storyboard animations inside.
The code looks like this:
if (bi.item.BitmapSource != null)
{
Image previewImage = new Image();
previewImage.Source = bi.item.BitmapSource;
itemPane.ItemPreviewCanvas.Children.Add(previewImage);
} else
if (bi.item.VectorSource != null)
{
UserControl previewControl = bi.item.VectorSource;
itemPane.ItemPreviewCanvas.Children.Add(previewControl);
}
Or it is not possible to share same control in different places, then what is the best way to make a copy, or the best way to store vector data.
Thanks in advance