Note that there are some explanatory texts on larger screens.

plurals
  1. POData loss during WPF clipboard operations
    text
    copied!<p>I am working with a <code>FlowDocument</code> in a WPF <code>RichTextBox</code>. Some of the flow document elements are created using subclasses of the <code>System.Windows.Documents</code> framework classes and all of the elements use the <code>Tag</code> property to store additional data.</p> <p>If I use a XamlWriter to serialize a document tree, everything is correctly reflected in the resulting <code>Xaml</code> output.</p> <p>However, if I simply copy and paste within the <code>RichTextBox</code>, although the pasted elements are visually identical to those from which they were copied, the clipboard operation discards all my additional data. Specifically, all the subclassed elements are pasted as instances of their base framework types and none of them have data in their <code>Tag</code> property.</p> <p>This suggests that a WPF clipboard operation on a <code>RichTextBox</code> does not use <code>XamlWriter</code> for serialization, despite the fact that the serialized clipboard data identifies its format as "Xaml".</p> <p>I imagine that the reason for this behavior is to ensure a common denominator when pasting into other Xaml-aware applications that do not necessarily have knowledge of my custom types. But I need to implement a richer copy / paste mechanism for use within my application.</p> <p>I guess I can probably intercept the copy event and add clipboard data in a custom format, which is subsequently applied in the paste event. However, this presents its own complications, as elements may need to be wrapped before pasting (for example inline elements that are pasted into a block element context).</p> <p>So, I am hoping to avoid reinventing the wheel and would appreciate any advice on how to get this to work using the existing framework infrastructure.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload