提出问题提出问题
 

已答复Cloning UIElements

  • 2007年12月18日 17:41ZiggyShort 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

     

    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?

答案

  • 2007年12月18日 17:47TomGiam 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复

    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

     

全部回复

  • 2007年12月18日 17:47Ckiszka 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    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 

     

  • 2007年12月18日 17:47TomGiam 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复

    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

     

  • 2007年12月18日 19:39ZiggyShort 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    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!