Problem Statement
Store WPF Richtextbox formatted text in Database and use the text in DB for writing to MS word.
Introduction : RichTextbox and Flow Document
WPF Richtextbox allow you to write formatted rich text like Bold, Italic, colors,Bulleted text etc.
Whatever we type in RichTextBox will be bind to FlowDocument property. As per the MSDN Definition :
“ Flow documents are designed to optimize viewing and readability. Rather than being set to one predefined layout, flow documents dynamically adjust and reflow their content based on run-time variables such as window size, device resolution, and optional user preferences. In addition, flow documents offer advanced document features, such as pagination and columns. This topic provides an overview of flow documents and how to create them.”
For more information you can go through the MSDN link on Flow Document.
https://msdn.microsoft.com/en-us/library/aa970909%28v=vs.100%29.aspx
Above example will give you basic understanding of FlowDocument.
One question always comes while using Richtextbox is about scrollbars.
Store WPF Richtextbox formatted text in Database and use the text in DB for writing to MS word.
Introduction : RichTextbox and Flow Document
WPF Richtextbox allow you to write formatted rich text like Bold, Italic, colors,Bulleted text etc.
Whatever we type in RichTextBox will be bind to FlowDocument property. As per the MSDN Definition :
“ Flow documents are designed to optimize viewing and readability. Rather than being set to one predefined layout, flow documents dynamically adjust and reflow their content based on run-time variables such as window size, device resolution, and optional user preferences. In addition, flow documents offer advanced document features, such as pagination and columns. This topic provides an overview of flow documents and how to create them.”
For more information you can go through the MSDN link on Flow Document.
https://msdn.microsoft.com/en-us/library/aa970909%28v=vs.100%29.aspx
Above example will give you basic understanding of FlowDocument.
One question always comes while using Richtextbox is about scrollbars.
WPF document works exactly as the MS Word. Do we find the horizontal scrollbars for the page in MS word ?. Page width will be fixed in MSWord. And whatever we type after the end of line, it will come to the next line.But still we can get the scrollbars using converters, behaviors and setting page width for Flow Document.
We can insert the images and shapes also.
You can go through this link for more detailed information about FlowDocument.
Problem Overview :
When we type text in WPF Richtextbox, it gives in the form of flowdocument property. But we need the formatted text which has to be saved in DB and the saved text in the db has to be written to MS Word.
Solution
1. Get the WPF toolkit dll from http://wpftoolkit.codeplex.com/ .
2. Add the dll as reference.
3. Use WPF Richtextbox.
4. Use XAML Formatter out of 3 formatter available.
5. Save same text in DB.
6. While writing to word document use InsertXML.
Here is an example to bind the text to a property in viewmodel and same property can be loaded in another richtextbox. Also a small piece of code which gives insight about how to write the same text in xml format to word.
License information
WPF toolkit is having Microsoft Public License which is an open source license but you need to keep the license information in your application.
WPF toolkit is having Microsoft Public License which is an open source license but you need to keep the license information in your application.
No comments:
Post a Comment