Cloning UIElements
-
Tuesday, December 18, 2007 5:41 PM
In my XAML I create a row of objects, which I wish to replicate.
eg. Buttons TextBoxes ComboBoxes Menus etc.
Is there an easy way of cloning the objects?
eg. Text on buttons, ReadOnly attributes, Events, Menu Contents?
All Replies
-
Tuesday, December 18, 2007 5:47 PM
Do you want to visualy clone with no behaviours? If so use a visual brush. Then fill a rectangle with your visual brush resource. If you need an example let me know.
-- Chris
-
Tuesday, December 18, 2007 5:47 PM
You can use this for cloning UIElements:
public static UIElement cloneElement(UIElement orig){
if (orig == null) return (null); string s = XamlWriter.Save(orig); StringReader stringReader = new StringReader(s); XmlReader xmlReader = XmlTextReader.Create(stringReader, new XmlReaderSettings()); return (UIElement)XamlReader.Load(xmlReader);}
Some attributes do have a clone method, like imageBrush for example.
Tom
-
Tuesday, December 18, 2007 7:39 PM
Thanks Tom,
That has helped me out enormously.
Only thing is: if I am hosting Windows.System.Forms controls in WindowsFormHost tag, they do not get handled; but there's only a few of those, which I handle manually.
Thanks again!

