1

I have a Grid containing several controls, the most important being three image controls. I need to make a duplicate of this Grid. Serializing by saving the XAML in a MemoryStream doesnt seem to help because, obviously, when I set the source of the Image Control in the code behind at runtime, this change is not reflected in the XAML designer code. [Technically it is, but as

<Image.Source> System.Windows.Interop.InteropBitmap</Image.Source>

and I get some wierd exception] So, how can I serialize my Image control? More generally, how can I Clone my Grid control to reflect any changes to the UI that happened after the window loaded?

DrMaxB
  • 540
  • 1
  • 3
  • 13

1 Answers1

0

If I understood your question properly, I think you just need to create a clone of your grid at runtime. If so take a look at these threads How can you clone a WPF object?

http://social.msdn.microsoft.com/Forums/en-HK/wpf/thread/e1a63ed2-a432-4c46-8f3b-4f172702cd7c

Use this function to clone an Object

public static T DeepClone<T>(T from)
    {
        using (MemoryStream s = new MemoryStream())
        {
            BinaryFormatter f = new BinaryFormatter();
            f.Serialize(s, from);
            s.Position = 0;
            object clone = f.Deserialize(s);

            return (T)clone;
        }
    }

above function was by Arcturus

Community
  • 1
  • 1
Sylens
  • 1,097
  • 8
  • 31