I want to give two small "why not" examples to the question.
Consider the following XAML snippet:
<DockPanel LastChildFill="False">
<TextBlock DockPanel.Dock="Right" Text="Test"/>
</DockPanel>
The dependency properties LastChildFill
and Text
are relatively easy, since they somehow belong to their object.
However, the DockPanel.Dock
is an attached property, so the DependencyObject
where it is attached to is potentially unaware of its existence. An arbitrary attached property can be attached to an arbitrary dependency object. The property does not belong to the object, but ignoring it on copy would lead to a change in the resulting layout.
Second example:
<Border>
<ContentPresenter Content="{Binding SomeObject}"/>
</Border>
There may be a DataTemplate for the type of SomeObject
, so consequently a visual tree will be constructed, but SomeObject
itself is not a WPF specific object, so what is your semantic expectation on getting a deep-copy of the border node?
Generally you may want to be more specific whether you want to deep-copy the logical tree or the visual tree. Your question tends towards the logical tree, but I suspect you are more interested in copying visual presentation of your layout. Consult your favorite search engine for more details on the matter. Here are two random points to start with: MSDN on WPF Trees and WPF tutorial on logical and visual tree.