how do i get the richtext box's content with all the formatting intact.
i used a TextRange object to get the content out of the richtext box but wen i get its .text property all its formatting is gone ... how do i get the formatted content in richtext box in wpf.
RichTextBox operates on FlowDocuments. You can get underlying FlowDocument from RichTextBox.Document property.
Related
I have written a text editor in WPF based on the WPF RichTextBox.
Everything works well. With BOLD, ITALIC etc., FontSize, FontFamily, TextAlignment and Indentation there are no problems.
But:
LineSpacing does not work! I can set the LineSpacing with Paragraph.LineHeight. When I save the text file in RTF format and load it again, the LineSpacing disappears. When loading, the corresponding RTF statement '\slnnn' is deleted.
If I load an RTF file from another text editor, the LineSpacing disappears also.
I know that I don't have the problem if I save the content of the RichTextBox as an XAML package and load it again. But then I am no longer compatible with other TextEditors.
Does anyone know a solution?
I am having a WPF application, in which i am using RichTextBox and binding it to a field in the database which contains the data as a HTML text. Also i applied TextFormatter="{StaticResource HtmlFormatter}" for the RichTextBox. Now if in the field i have a paragraph with some html styles applies like font color, font size etc they are supposed to appear in the same style.But i am not able to see the font size in the application, though font style and font color are applied.
Can anybody help on this ?
Thanks in advance!!!
Is there any way to open a Word Document in a TabItem of TabControl in WPF?
Add a DocumentViewer control to your TabItem which can host fixed documents like xps documents. You might need to convert your word document to xps document and then load it into the DocumentViewer control to display it.
More information can be found in this article.
It seems DocumentViewer cannot be converted to type System.Windows.Forms.Control when trying to add it to the TabItem's controls collection.
i am trying to write a control template where i want a label for text box on top of the textbox. So i invite your suggestions for how to achieve this.
so far i did that using a stack pannel with vertical orientation and then added textblock and text box. Like wise i created 45 stackpannels. So i dont want to go like that. instaed i want to write a control template where i can have label and text box and then set label value and text box value.
my:CustomControl labelText="First Name:" TextBoxText="john Doe" />
any ideas are greatly appreciated.
Thanks.
You can make a UserControl with DependencyProperties for Text and Label, put your StackPanel in it, and bind the label and textbox to the dependency properties.
Make sure the Text property has FrameworkPropertyMetadata.BindsTwoWayByDefault
Have a look at the Silverlight Toolkit
It includes both HeaderedContentControl and DataField controls. The DataField is mainly for use with DataForm, but as far as I know, you can use it any way you like. The HeaderedContentControl I haven't tried myself, but it could be just what you are looking for.
I have a bound textbox and I need to change its associated display label to bold upon the presence of any content. I dont want to use javascript if at all possible.
Thanks
Why would javascript be involved?
Anyway, if this is really wpf, bind the FontWeight property of your label to the textbox's text property, using custom converter that converts null/empty strings to Normal font weight, and non-null/non-empty to Bold.