Formular una preguntaFormular una pregunta
 

RespondidaCloning UIElements

  • martes, 18 de diciembre de 2007 17:41ZiggyShort Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

     

    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?

Respuestas

  • martes, 18 de diciembre de 2007 17:47TomGiam Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida

    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

     

Todas las respuestas

  • martes, 18 de diciembre de 2007 17:47Ckiszka Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    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 

     

  • martes, 18 de diciembre de 2007 17:47TomGiam Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida

    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

     

  • martes, 18 de diciembre de 2007 19:39ZiggyShort Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    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!