Data loss during WPF clipboard operations

I work with FlowDocumentin WPF RichTextBox. Some elements of the flow document are created using subclasses of classes System.Windows.Documents, and all elements use the property Tagto store additional data.

If I use XamlWriter to serialize a document tree, everything will be correctly reflected in the output Xaml.

However, if I simply copy and paste into RichTextBox, although the inserted items are visually identical to the ones from which they were copied, the clipboard operation discards all my additional data. In particular, all subclasses of elements are inserted as examples of their basic framework types, and none of them have data in the property Tag.

This suggests that WPF's clipboard operation is RichTextBoxnot used XamlWriterfor serialization, even though serialized clipboard data defines its format as “Xaml”.

I assume that the reason for this behavior is to provide a common denominator when pasted into other Xaml-enabled applications that do not necessarily have knowledge of my custom types. But I need to implement a richer copy / paste mechanism for use in my application.

, , . , , , (, , ).

, , , .

+3

Source: https://habr.com/ru/post/1755591/


All Articles