Why can't I paste text copied from WPF FlowDocumentScrollViewer or Reader?

In the previous question, I was trying to figure out how to bind an ObservableCollection to a control so that I can see all the rows and select all the rows and copy them from the content control. The answers to this question eventually made me look (and it seems the behavior) that I wanted using the following XAML. (I tried both FlowDocumentReader and FlowDocumentScrollViewer - they behave the same.)

<Grid> <FlowDocumentScrollViewer> <FlowDocument > <Paragraph> <ItemsControl ItemsSource="{Binding ErrorMessages, Mode=OneWay}" /> <Run Text="{Binding /, Mode=OneWay}" /> </Paragraph> </FlowDocument> </FlowDocumentScrollViewer> </Grid> 

ErrorMessages is my ViewModel property, which returns an ObservableCollection <string> . It is bound correctly to the ItemsSource , and the <Run> element is bound to every row in the collection. It looks good, lasts a long time. It was so close that I answered the last question, but I still have one problem.

I right-click and a menu appears with the options "Select All" and "Copy". Using Select All, it really selects all the text, choosing Copy Problems, there are no errors, but when I go to NotePad (or Word, or TextPad, etc. Or RTB in the form) and try to paste the text, nothing appears . As a newbie to WPF, I suspect I'm doing something wrong, but I don't know what it is. There is no such thing as a "carefree" text?

[Edit -June 22 2011] For other reasons, I changed the code to use the TextBlock via the ItemTemplate inside the ItemsControl, as shown below, but I still can not copy and paste.

 <DataTemplate x:Key="StringCollection"> <TextBlock TextWrapping="Wrap" Text="{Binding}" TextAlignment="Left"/> </DataTemplate> <!--... now down in the ItemsControl--> <ItemsControl ItemsSource="{Binding ReceivedData, Mode=OneWay}" ItemTemplate="{StaticResource StringCollection}" /> 
+6
source share
1 answer

<Run> element is bound to each row in the collection.

It should only snap to the current item.

In any case, your document does not actually contain any text, if all you have is ItemControl. What for? Because any UIElements inside the document are automatically wrapped in a BlockUIContainer or InlineUIContainer and are no longer considered text.

In general, the contents are copied as XAML, RTF, UnicodeText and Text (I could notice them, but there could be other formats), you can try to put several Runs in the document, their text should be copied correctly and Clipboard.GetText() must return their contents.

+3
source

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


All Articles