flowdocument

Copying one FlowDocument to Second FlowDocument

為{幸葍}努か 提交于 2019-12-04 21:56:27
问题 How can i copy the contents of one FlowDocument to another FlowDocument below is what i tryed foreach (var blk in fd1.Blocks) { fd2.Blocks.Add(blk); } fd1 is FlowDocument1 and fd2 is FlowDocument2. But i get the below error. Collection was modified; enumeration operation may not execute. Thanks Arvind 回答1: Because each Block is 'owned' by a FlowDocument, it cannot just be added to another. You must serialize it and then deserialize it, which breaks the bond with the original FlowDocument,

WPF Printing - Multipage Invoice Via Flowdocument, Paginator and FixedDocument

…衆ロ難τιáo~ 提交于 2019-12-04 19:59:17
We're currently using WPF to create a multi-page invoice document, to then be printed / exported via XPS. The route we've taken to achieve this is to create a UserControl containing a standard ListBox etc displaying the Invoice lines, this is then included in a FlowDocument inside BlockUIContainer tags. When this FlowDocument is placed inside FlowDocumentScrollViewer tags in a window, it works perfectly, with the databound content of the UserControl displaying properly. However, when we try to create the same FlowDocument in code, it fails with a "'Cannot create unknown type '{clr-namespace

How can I create subclass of class Inline ? (the one used in FlowDocument)

不羁岁月 提交于 2019-12-04 05:36:52
In WPF I would like to create custom Inline implementation. From documentation of Inline : "An abstract class that provides a base for all inline flow content elements." Classes like Figure , Run or Span inherit from Inline . My custom class inheriting from Inline would be something like '2 lined Run'. I have special needs for flow of document and this seems to be the only way. However I don't know where to start: Inline does not define any members! It is abstract class so it is meant to be inherited but there is no documentation on how to inherit from it. Not in MSDN and nowhere else where I

creating an XPS Document from a FlowDocument and attach it on the fly

若如初见. 提交于 2019-12-04 04:30:17
I have a FlowDocument that I want to convert to an XPS Document and attach it to an e-mail and send it all together. I'm using this code public static MemoryStream FlowDocumentToXPS(FlowDocument flowDocument, int width, int height) { MemoryStream stream = new MemoryStream(); using (Package package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite)) { using (XpsDocument xpsDoc = new XpsDocument(package, CompressionOption.Maximum)) { XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false); DocumentPaginator paginator = (

How can we show .rtf or .doc as flowdocument in WPF?

巧了我就是萌 提交于 2019-12-04 04:08:41
It is for the help section of the application. I am thinking to put flowdocumentReader to show the help document. But is it possible to show .rtf or any .doc to show in Flowdocument.Or is it neccesary to create a flow document in Xaml. Please help. Thanks, Something on these lines will do the job for you where documentPath is your rtf file path: FileStream fileStream = File.Open(documentPath, FileMode.Open, FileAccess.Read, FileShare.Read); FlowDocument flowDocument = new FlowDocument(); TextRange textRange = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd); textRange.Load

Binding a list in a FlowDocument to List<MyClass>?

五迷三道 提交于 2019-12-04 03:35:46
I have a FlowDocument containing stuff bound to my ViewModel like this: <FlowDocumentReader> <FlowDocument> <Paragraph> <Run Text="{Binding MyTextProperty}"/> </Paragraph> </FlowDocument> </FlowDocumentReader> Now I want to display a List of class using some kind of DataTemplate, but got no idea how to start. Say I got a class like: public MyClass { String Title {get;set;} String FlowText {get;set;} } public List<MyClass> MyList {get;set;} And I'd like to bind this to the FlowDocument List, like this: <FlowDocumentReader> <FlowDocument> <List Items="{Binding MyList}"> <Bold><Run Text="{Binding

Detect if a RichTextBox is empty

泪湿孤枕 提交于 2019-12-04 00:32:03
What is the best way to detect if a WPF RichTextBox/FlowDocument is empty? The following works if only text is present in the document. Not if it contains UIElement's new TextRange(Document.ContentStart, Document.ContentEnd).IsEmpty You could compare the pointers, which is not all too reliable: var start = rtb.Document.ContentStart; var end = rtb.Document.ContentEnd; int difference = start.GetOffsetToPosition(end); This evaluates to 2 if the RTB is loaded, and 4 if content has been entered and removed again. If the RTB is completely cleared out e.g. via select all -> delete the value will be 0

How can I hide a Paragraph in a FlowDocument?

故事扮演 提交于 2019-12-04 00:09:52
问题 Is there any way to use databinding to show or hide a Paragraph within a FlowDocument? (I want to use MVVM, but with a FlowDocument as my view.) Paragraph doesn't have a Visibility property. I'm not sure what else to look for. 回答1: I tried Chris Bova's answer, but it had a couple problems: Text selection didn't work right The text inside didn't flow like a paragraph My solution was to add and remove the paragraph from the flow document. The steps are: Name the flow document (ie flowDocument)

Inserting an HTML fragment into a WPF FlowDocument

蹲街弑〆低调 提交于 2019-12-03 17:17:50
问题 I'm dynamically building a WPF FlowDocument from a datasource. One of the data elements is a fragment of HTML - I need to figure out a way to parse that and insert it into my FlowDocument. I've found HTMLToXAMLConverter which will return a XAML representation of the HTML, but I'm still not sure how to best go about instantiating that XAML fragment so I can insert it into my FlowDocument. 回答1: Answered my own question... System.Windows.Markup.XamlReader.Parse() 回答2: Had same problem, but had

How Can I Get a TextPointer from a mouse click in a FlowDocument

你。 提交于 2019-12-03 16:15:14
I would like to get the word that a user has clicked on in a FlowDocument. I am currently adding an event handler to every Run in the document and iterating through the TextPointers in the Run that was clicked, calling GetCharacterRect() on each one and checking if the rectangle contains the point. However, when the click occurs near the end of a long Run this takes > 10 seconds. Is there any more efficient method? I'd say the easiest way is to use the Automation interfaces: using System.Windows.Automation.Peers; using System.Windows.Automation.Provider; FlowDocument flowDocument = ...; Point