开发者

MS Word pagination using Multiple wpf RichTextBox

开发者 https://www.devze.com 2023-01-27 05:15 出处:网络
My aim is to make a editor behave similarto MS-Word.Wpf RichTextBox is a wonderful control for it.By placing it inside a ScrollViewer,we can make it editable.(Like a notepad).But I need MS-Word like p

My aim is to make a editor behave similar to MS-Word.Wpf RichTextBox is a wonderful control for it.By placing it inside a ScrollViewer,we can make it editable.(Like a notepad).But I need MS-Word like pages.One effective way probably is to apply style to scrollViewer such that we create a look and feel of multiple pages on richtextbox but I dont know how to do it.What we are doing in the project is to use a documentViewer. Inside a FixedPage,create a Header(Canvas),Body(WpfRichTextBox),Footer(Canvas). And thus create multiple pages,and by subscribing to RichTextBox sizechanged event, we are manually doing the pagination i.e move the blocks from one page to another开发者_如何学运维 when height has changed. Do you see any better approach in doing this? Does using multiple richtextboxes hamper my performance?


@WpfProgrammer This is the good approach I would say. Say if you have 1000s of pages then, there will definitely be a performance problem. For avoiding that problem, you need to do demand paging.

Virtual Paging :
1. You need to construct a page table, which will contains pages. Each page will contains information about the controls, images, their positions, dimension and Styles for the page. [All serializable data]

2. Virtual Pages - You need to de-serialize all the data for the page and create a page with RichTextBox. Virtual Pages are nothing but, pre-cached pages that are going to be rendered. Say for example. If I'm in 1st page. Then, I'll de-seriealize next 3 consecutive pages and have them in a collection. Then, repeat this procedure for consecutive page movements. Adding some logic using Most Frequently Used collection. It will be fast enough. In the case of 1000's of pages. You can collapse those non-dirty or never visited pages. That could yield little more performance. If performance is far more concern for low hardwares. Then, you should consider cleaning.

3. Cleaning - Cleaning is the process of identifying LFU pages and remove them. This would be very helpful if performance is more pronounced.


Hi Tameem Set the min height,width of the richTextBox to A4 size(lets say). Subscribe to RichTextBox Size Changed event.As soon as the content exceeds,this event gets fired.Then I take the last block of previous page and push it to the first block of next page.(Remember if page doesnot exist, you need to create new page then add it as first block).And also the focus should be changed to the new page.(because if you press enter at the last RTB, you expect the focus to be there in the new page.).When the user deletes a block in some page(say 2nd),then you need to add all the blocks of bottom pages to this page,so that our pagination logic will push the blocks down again and adjust. I can share some piece of code if you need further help.

0

精彩评论

暂无评论...
验证码 换一张
取 消