Sharing same vector control between different places

Posted by Alexander K on Stack Overflow See other posts from Stack Overflow or by Alexander K
Published on 2010-05-28T11:01:49Z Indexed on 2010/05/28 11:01 UTC
Read the original article Hit count: 214

Filed under:
|
|

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);
    }

Thanks in advance

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about bitmap