52974

How to copyclone a UIElement and keep the layout/render information?

I wish to copy a complex data-bound UIElement but keep the Binding, Layout and Rendering information from the original UIElement.

Creating a new UIElement seems inefficient since I would have to do another complete Binding/Measure/Arrange/Render pass.

The closest I've got so far is to create a new DrawingVisual, open it for rendering, and DrawDrawing using the source UIElement DrawingGroup.

DrawingVisual dv = new DrawingVisual(); DrawingGroup dg = VisualTreeHelper.GetDrawing(SourceElement); using (DrawingContext dc = dv.RenderOpen()) { Drawing d = dg.Children[0]; dc.DrawDrawing(d); } return dv;

Is this a good approach and will it work for complex UIElements (e.g. lots of Panels within Borders, custom Controls etc etc)?

To give you a context, I am making a DocumentPaginator which is working well, but inefficeintly due to the recreation of identical UIElements.

Thanks in advance, Pete

Answer1:

If it's only for presentation purposes, you can use a VisualBrush. More information can be found here, here, and here. It even reflects any live updates made to the attached visual.

Recommend

  • Save image of whole ListView
  • Configure WAF Application Gateway in front of App Services [closed]
  • Tracking screen recorder in windows app
  • javafx 3d performance large data set
  • Pytest/Allure - How to generate testcase description?
  • Rails 5 - Google Maps - Javascript error - initMap is not a function - fixing one js issue creates a
  • How to render a pixel array most efficiently to a window in c++?
  • Creating a DropDownList
  • Who propagate bugfixes across branches (corporate development)?
  • Bad request using file_get_contents for PUT request in PHP
  • D3 nodes and links from JSON with nested arrays of children
  • How to create a file in java without a extension
  • Alert pop up with LWUIT
  • NHibernate Validation Localization with S#arp Architecture
  • Scrapy recursive link crawler
  • Using jQuery closest() method with class selector
  • ilmerge with a PFX file
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Adding a button at the bottom of a table view
  • Display issues when we change from one jquery mobile page to another in firefox
  • Nant, Vault & Windows Integrated Authentication
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Read text file and split every line in MSBuild
  • req.body is undefined - nodejs
  • Counter field in MS Access, how to generate?
  • Get object from AWS S3 as a stream
  • Java applet as stand-alone Windows application?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • MySQL WHERE-condition in procedure ignored
  • Can I make an Android app that runs a web view in Chrome 39?
  • Javascript + PHP Encryption with pidCrypt
  • Websockets service method fails during R startup
  • Adding custom controls to a full screen movie
  • Comma separated Values
  • Error creating VM instance in Google Compute Engine
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • LevelDB C iterator
  • Linking SubReports Without LinkChild/LinkMaster