RichText control that is editable, copy/pastes, serializable? RRS feed

  • Question

  • Is there a RichText control (has text w/ font size and color) that has these qualities:
    1) Editable by user
    2) Accepts entries pasted from word and Internet Explorer
    3) Its text/content can be stored in SQL server
    4) Can be used in silverlight somehow (if can not be added in designer, can it be added to another control's content dynamically and work?)

    RichTextBox class may do it, but I am not sure if it is usable in silverlight (http://msdn.microsoft.com/en-us/library/cc295153(Expression.30).aspx

    Also, is there no easier way of storing object (content) in the database than having to know the exact structure, having to traverse object, making XML from it and storing that? 
    Friday, January 15, 2010 2:26 PM


All replies

  • hi,
              First i would like to let you know that RichTextBox of WPF is the only control that will suit your needs, ( unless in future someone makes a custom user control for it.
    Now coming to your question :

    1 . RichTextBox is ofcourse very much editable

    2.  RichTextBox by default can accpet paste from word and IE.

    3. I have created a sample Custom RichTextBox for you which can give you the string representation of its contents and also set its contents from from the saved string. So you can now save this xaml string into any presistence repository, including SQL server DB.

    4. You cannot use it directly in silverlight, because silverlight before version 4.0 does not support the RichTextBox Class. U can use many custom richtextbox available in the net for silverlight. you may see this : http://www.codeplex.com/richtextedit or  http://www.vectorlight.net/demos/richtextbox.aspx

    With Silverlight 4.0 you can Get this RichTextBox : http://michaelsync.net/2008/05/04/silverlight-rich-text-editor-demo
    public class CustomRichTextBox : RichTextBox
            public string GetDocumentXamlString()
                var flowDocument = this.Document;
                return XamlWriter.Save(flowDocument);
            public void SetDocumentXamlString(string xamlString)
                FlowDocument document = null;
                    var stringReader = new StringReader(xamlString);
                    var xmlReader = new XmlTextReader(stringReader);
                    document = (FlowDocument)XamlReader.Load(xmlReader);
                    throw new Exception("Could not parse the xaml string");

    • Proposed as answer by Saraf Talukder Friday, January 15, 2010 3:25 PM
    • Marked as answer by Pitiko2 Saturday, January 16, 2010 2:21 AM
    • Unmarked as answer by Pitiko2 Saturday, January 16, 2010 1:07 PM
    Friday, January 15, 2010 3:24 PM
  • I tested their demos. They are out dated and not usable in silverlight 3 or 4 beta. I try to use RichTextArea dynamically.
    Saturday, January 16, 2010 1:10 PM
  • Hi Pitiko2,

    The following is the MSDN documents on RichTextArea class:

    Hope this helps.

    Linda Liu
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Pitiko2 Thursday, January 28, 2010 6:05 AM
    Friday, January 22, 2010 3:15 PM