flowdocument

Retaining font size when loading/saving RTF in WPF

拜拜、爱过 提交于 2021-02-19 00:50:46
问题 Consider the following RTF document {\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fswiss\fprq2\fcharset0 Segoe UI;}{\f1\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs22 Sample Text\f1\fs20\par } It contains "Sample Text" in font Segoe UI 11 pt. Now when I load and then save the document using WPF's FlowDocument and TextRange.Load() and .Save(), respectively, the font size is reduced to 10.5pt. Is there any way to retain the original font size

Retaining font size when loading/saving RTF in WPF

自古美人都是妖i 提交于 2021-02-19 00:48:03
问题 Consider the following RTF document {\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fswiss\fprq2\fcharset0 Segoe UI;}{\f1\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs22 Sample Text\f1\fs20\par } It contains "Sample Text" in font Segoe UI 11 pt. Now when I load and then save the document using WPF's FlowDocument and TextRange.Load() and .Save(), respectively, the font size is reduced to 10.5pt. Is there any way to retain the original font size

How to show a flow document using a DocumentViewer?

坚强是说给别人听的谎言 提交于 2021-02-07 09:32:33
问题 I have a simple flow document in my resources, FlowDocument1.xaml : <FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ColumnWidth="400" FontSize="14" FontFamily="Georgia"> <Paragraph> Test </Paragraph> </FlowDocument> And I want to show this document in a DocumentViewer . I searched for a property that takes path but I couldn't find one. And the following throws an exception: <DocumentViewer x:Name="TestViewer" Document="Resources/FlowDocument1.xaml" /> How can I

How to show a flow document using a DocumentViewer?

纵饮孤独 提交于 2021-02-07 09:32:05
问题 I have a simple flow document in my resources, FlowDocument1.xaml : <FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ColumnWidth="400" FontSize="14" FontFamily="Georgia"> <Paragraph> Test </Paragraph> </FlowDocument> And I want to show this document in a DocumentViewer . I searched for a property that takes path but I couldn't find one. And the following throws an exception: <DocumentViewer x:Name="TestViewer" Document="Resources/FlowDocument1.xaml" /> How can I

FlowDocument Xml serialization

北城以北 提交于 2021-01-29 11:10:30
问题 I have FlowDocument as a part of another composite object, what must be serializable. [Serializable] public class RichTextSerializationWrapper { public FlowDocument Document { get; set; } } So, I want serialize RichTextSerializationWrapper as follows: var serializer = new XmlSerializer(typeof(RichTextSerializationWrapper)); TextWriter writer = new StreamWriter(fileName); serializer.Serialize(writer, richTextSerializationWrapper); writer.Close(); And I, of course, get exception: There was an

How to work with RichTextBox in WPF

断了今生、忘了曾经 提交于 2020-06-13 10:05:14
问题 I have a WPF application in which I want to convert a TextBox into a RichTextBox. I have already written the following lines of code: <RichTextBox> <FlowDocument> <Paragraph> <Run Text="{Binding GeneralDescription}" /> </Paragraph> </FlowDocument> </RichTextBox> This has the effect that the string GeneralDescription is displayed and I can edit and format it. Now I have the problem that when I mark a part of the text, format it (e.g. make it bold), save the document and re-open the document,

FlowDocument replace Section?

孤者浪人 提交于 2020-01-25 03:41:08
问题 I have a FlowDocument with two Sections. One is named 'Inhalt'. Trying to replace it with another Section doesn't seem to work: InfoBoxAuditorium.Inhalt = InfoBoxAuditorium.Resources["DokumentWohnzimmer"] as Section; What am I doing wrong? 回答1: Just for the records. I solved this by surrounding the FlowDocument with another Grid. The first row contains the stuff I don't want to be replaced. Easy but it does its job. 来源: https://stackoverflow.com/questions/3781109/flowdocument-replace-section

Export FlowDocument with UIElement to rtf

末鹿安然 提交于 2020-01-24 17:13:11
问题 I am trying to export a FlowDocument which contains a grid to rtf. I used the following code using (FileStream fs = new FileStream(@"C:\demo.rtf", FileMode.OpenOrCreate, FileAccess.Write)) { TextRange textRange = new TextRange(doc.ContentStart, doc.ContentEnd); textRange.Save(fs, DataFormats.Rtf); } However I am getting a blank document. How can this be solved? 回答1: I had a similar issue recently and the culprit turned out to be the FileMode.OpenOrCreate It should have been FileMode.Create

How to get the HEIGHT of the Run or Paragraph

喜夏-厌秋 提交于 2020-01-23 01:34:21
问题 I found the Run or Paragraph in FlowDocument and now I need to know the HEIGHT of it. i.e. while (navigator.CompareTo(flowDocViewer.Document.ContentEnd) < 0) { TextPointerContext context = navigator.GetPointerContext(LogicalDirection.Backward); Run run = navigator.Parent as Run; // I need to get HEIGHT of Run in pixels somehow Is it possible to do in fact? Thank you! 回答1: A little function i am using. The input is a string containing a Section. You can easily render other blockelements like

Performance Flowdocument with Table with a big amount of data

[亡魂溺海] 提交于 2020-01-16 01:02:14
问题 What I try to do: Generate a report based on data from the database, and then be able to view it and print it. (This in WPF C#) How I do it: (dynamically, via code) My Window is simple, it's just a FlowDocumentPageViewer with nothing in it. I load the data from the database Use LINQ to group it all properly Initialize a new Flowdocument Make a Table, with a RowGroup Loop my LINQed data and fill the RowGroup with TableRows that contain cells with the required data Add the Table to the