Formula una domandaFormula una domanda
 

Con rispostaCloning UIElements

  • martedì 18 dicembre 2007 17.41ZiggyShort Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     

     

    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?

Risposte

  • martedì 18 dicembre 2007 17.47TomGiam Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta

    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

     

Tutte le risposte

  • martedì 18 dicembre 2007 17.47Ckiszka Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     

    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 

     

  • martedì 18 dicembre 2007 17.47TomGiam Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta

    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

     

  • martedì 18 dicembre 2007 19.39ZiggyShort Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     

    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!