This is a migrated thread and some comments may be shown as answers.

RadRichTextBox and RadDataEntry

2 Answers 76 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
victor palomares
Top achievements
Rank 1
victor palomares asked on 02 Apr 2014, 05:00 PM
Hi,
I am trying to use RadRichTextbox with RadDataEntry.
On the EditorInitializing event I set the editor to be a RadRichEditor for a particular string field.
However since there is no property for the Text in the editor I am not sure how to handle the binding in this case.

Any pointer will be much appreciated. 
Thanks

2 Answers, 1 is accepted

Sort by
0
victor palomares
Top achievements
Rank 1
answered on 03 Apr 2014, 09:14 AM
I figured it out by myself. Instead of binding to RadRichTextBox I created a wrapper user control around it that controls the Text Properties

I put the solution in case is useful for anyone:

01.public partial class RtlfWrapper : UserControl
02.    {
03.        public event EventHandler RtlfTextChanged;
04. 
05.        public RtlfWrapper()
06.        {
07.            InitializeComponent();
08.        }
09. 
10.        private void radRichTextBox1_DocumentContentChanged(object sender, EventArgs e)
11.        {
12.            OnRtlfTextChanged();
13.        }
14. 
15. 
16.        public string RtlfText
17.        {
18.            get
19.            {
20.                var formatProvider = new RtfFormatProvider();
21.                return formatProvider.Export(radRichTextBox1.Document);
22.                 
23.            }
24.            set
25.            {
26.                radRichTextBox1.DocumentContentChanged -= radRichTextBox1_DocumentContentChanged;
27. 
28.                try
29.                {
30.                    ImportDocument(value);
31.                }
32.                catch
33.                {
34.                    InsertText(value);
35.                }
36. 
37.                OnRtlfTextChanged();
38.                radRichTextBox1.DocumentContentChanged += radRichTextBox1_DocumentContentChanged;
39.            }
40.        }
41. 
42.        private void ImportDocument(string value)
43.        {
44.            var formatProvider = new RtfFormatProvider();
45.            radRichTextBox1.Document = formatProvider.Import(value);
46.        }
47. 
48.        private void InsertText(string value)
49.        {
50.            var span = new Span(value);
51.            var paragraph = new Paragraph();
52.            var section = new Section();
53.            var document = new RadDocument();
54. 
55.            paragraph.Inlines.Add(span);
56.            section.Blocks.Add(paragraph);
57.            document.Sections.Add(section);
58. 
59.            radRichTextBox1.Document = document;
60.        }
61. 
62.        protected virtual void OnRtlfTextChanged()
63.        {
64.            var handler = RtlfTextChanged;
65.            if (handler != null) handler(this, EventArgs.Empty);
66.        }
67.    }
0
George
Telerik team
answered on 07 Apr 2014, 02:08 PM
Hello Victor,

I am glad that you found a solution to your problem. We appreciate that you are sharing it with the community.

Do not hesitate to let us know should you have any further questions.

Regards,
George
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
victor palomares
Top achievements
Rank 1
Answers by
victor palomares
Top achievements
Rank 1
George
Telerik team
Share this question
or