Note that there are some explanatory texts on larger screens.

plurals
  1. POLazy loading pages in DocumentReader
    primarykey
    data
    text
    <p>I have a table in sqlite database that contains some book pages. each book contains about 300-400 pages. each record in database has a field of a page content in flowDocument format.</p> <p>Now I want to load each book in documentRaader(like Adobe pdf reader) and due to the large number of pages, it is very slow.<br></p> <p>this is my code:</p> <pre><code>public void LoadBook() { FlowDocumentReader ViewContent = new FlowDocumentReader() FixedDocument fd = new FixedDocument(); ViewContent.Document = fd; DataTable dt = libraryclass.GetBookPages(); for (int i = 0; i &lt; dt.Rows.Count; i++) { string pagecontent = ReplaceText(dt.Rows[i]["Content"].ToString()); FlowDocument flow = ContentView.ConvertForView(pagecontent); flow.TextAlignment = TextAlignment.Justify; flow.FontSize = 18; PageContent page = new PageContent(); RichTextBox rich = new RichTextBox(); //rich.LineDown(); rich.IsReadOnly = true; rich.Document = flow; rich.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; rich.Margin = new Thickness(20, 70, 20, 70); //rich.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; rich.Width = 710; rich.BorderBrush = null; rich.BorderThickness = new Thickness(0); rich.Height = 840; fd.Pages.Add(page); page.Child = new FixedPage(); page.Child.Width = 750; page.Child.Height = 970; page.Child.Children.Add(rich); } } </code></pre> <p>Can I only load book pages that is currently showing each time and next/pre pages?</p> <p>Is there a control like android ViewPager in WPF?</p> <p>thanks in advance.</p> <p><strong>EDIT :</strong></p> <p>I changed the code and now I'm using xpsDocument with this code:</p> <pre><code>private void LoadBook() { DataTable dt = db.Select("Select Content From PageTBl where BookID = 3"); FlowDocument flow = new FlowDocument(); foreach (DataRow row in dt.Rows) { String content = row["Content"].ToString(); content = String.IsNullOrEmpty(content.Trim()) ? "&lt;FlowDocument xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Name=\"flowducument21\"&gt;&lt;Section/&gt;&lt;/FlowDocument&gt;" : content; FlowDocument fd = XamlReader.Load(new MemoryStream(Encoding.GetEncoding("utf-8").GetBytes(content))) as FlowDocument; flow.Blocks.Add(fd.Blocks.FirstBlock); } DocumentPaginator dpaginator = new CustomDocumentPaginator(((IDocumentPaginatorSource)flow).DocumentPaginator, new Size(793.5987, 1122.3987), new Size(96, 96), ""); MemoryStream stream = new MemoryStream(); Package package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite); var uri = new Uri(@"memorystream://myXps.xps"); PackageStore.AddPackage(uri, package); var xpsDoc = new XpsDocument(package); xpsDoc.Uri = uri; XpsDocument.CreateXpsDocumentWriter(xpsDoc).Write(dpaginator); FixedDocumentSequence fds = xpsDoc.GetFixedDocumentSequence(); DViewer.Document = fds; } </code></pre> <p>But it takes about 140 seconds to load. How to load it faster?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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