• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
.NET Framework Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
.NET Framework Developer Center > .NET Development Forums > Windows Presentation Foundation (WPF) > Cloning UIElements
Ask a questionAsk a question
Search Forums:
  • Search Windows Presentation Foundation (WPF) Forum Search Windows Presentation Foundation (WPF) Forum
  • Search All .NET Development Forums Search All .NET Development Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerCloning UIElements

  • Tuesday, December 18, 2007 5:41 PMZiggyShort Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

     

    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?

    • ReplyReply
    • QuoteQuote
     

Answers

  • Tuesday, December 18, 2007 5:47 PMTomGiam Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0

    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

     

    • ReplyReply
    • QuoteQuote
     

All Replies

  • Tuesday, December 18, 2007 5:47 PMCkiszka Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    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 

     

    • ReplyReply
    • QuoteQuote
     
  • Tuesday, December 18, 2007 7:39 PMZiggyShort Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    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!

     

    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement