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

RadRichTextBox and LightSwitch Newbie Question

2 Answers 105 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 2
John asked on 15 May 2013, 08:14 PM

Hello,

I'm creating a LightSwitch project that is designed to move my e-sword study notes to my web site www.MyHebrewBible.Com (MHB). The study notes are in a field thats contains my notes which are formated as RTF. I'm struggling how to use the Telerik RadRichTextBox SilverLight Control this is the main reason for my question.

 

The database I've created with my LightSwitch App is a collection of rows that I want to process. The table (StudyNote) consists of four fields...

  1. ID: surrogate primary identity key
  2. BCV: (B)ook (C)hapter (V)erse. e.g. "Gen 1:1",
  3. CommentsRTF: My old e-Sword comments that have been persisted in Rich Text Format
  4. CommentsNew: What I want to use to hold my comments that I will eventually add to My Hebrew Bible website. The format (I presume) best fitted for this would be HTML.

Here's my Development Environtment: Visual Studio 2012 Update 2, SilverLight 5 & Telerik RadControls for Silverlight Q1 2013.

I mention this because the samples that I have found on the internet were based on prior versions of LS and things have changed. For example, a Silver Light Custom control can not be inside the LS project. Therefore I had to to create a seperate project which I called RadRichSilverLightClassLibrary. With in that project I created two Silverlight User Controls that utilized the Telerik RadRichTextBox controls.

Here are the steps I took to create this new project.

  1. Deleted the autogenerated Class1.cs file
  2. Added the necessary references
  3. Added a Silverlight User Control called ReadOnlyRtfDocumentViewer
  4. Dragged the RadRichTextBox control onto it and filled out the Wizard
  5. Added a Silverlight User Control called RichTextBoxHtmlDataProvider
  6. Dragged the RadRichTextBox control onto it and filled out the Wizard

For my esword LightSwitch Project, I did the following

  1. Created a Data Source based on the StudyNotes Resource table. This table I created and populated earlier using Sql Server Express 2012.
  2. Created a StudyNotesListDetail screen based on StudyNotes
  3. Changed the ContentRTF control to a custom control
  4. Selected the ReadOnlyRtfDocumentViewer User Control from the RadRichSilverLightClassLibrary Project
  5. Added the same Telerik references that I did to my library project. I'm not sure why this is necessary if the it already has these references. If I didn't add them, then the InitializeComponent method of the user controld would throw a Xaml Parse Exception ... the HtmlDataProvider was not found

QUESTIONS

  1. The way my LightSwitch application stands right now, is that I have not done anything special with the code behind. I didn't do anything else like go into the code behind and wire things up, because I don't know if I'm supposed to or not, or does this all get done declaritively with the Xaml? This is obviously a XAML newbee question. See the attached image.
  2. Right now my study note edit screen has a control for the RTF and empty control for the HTML. I want to also create an copy/paste button that will convert the RTF into HTML and paste into the new control. What I was wondering is if I can just do a batch and convert all the data to HTML and then decide which part of the HTML (if any) I want to keep. This would eliminate the user having to click a copy/paste button. Is this doable?
  3. One of the options is to save RTF data as XAML. It makes sense to have my study notes saved in HTML as that's what I website uses, but what are the advantages of saving data as XAML instead of as HTML? 

 
Thanks,
John

2 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 2
answered on 15 May 2013, 08:24 PM
here is a screen shot of my LightSwitch App
0
Iva Toteva
Telerik team
answered on 18 May 2013, 04:39 PM
Hi John,

The references that RadRichTextBox uses must be added to all projects that use the control, i.e. the one you declare your custom control and the ones that use it. Sometimes Visual Studio manages this case by adding the dlls that your code depends on behind the scenes (they are copied in the bin/obj folders, even though not explicitly referenced). RadRichTextBox, however, uses MEF to load format providers and does not have a dependency on the format providers. That is why Visual Studio does not handle this case.

As for your other questions:
1. If you have chosen a data provider from the wizard, it should have been added to the XAML. However, you need to set which property the data provider should be bound to, so as to wire the control with the data from the data base. In the attached solution, instead of a data provider, we have used the attached property telerik:XamlDataProvider.Source like this:

telerik:XamlDataProvider.Source="{Binding XamlContent, Mode=TwoWay}"
where XamlContent is the name of the field in the database.

You can use HtmlDataProvider and RtfDataProvider in the same way.

2. If I understand your question correctly, you can convert RTF to HTML programmatically and vice versa. Basically, you can import the content using one of the providers and export the resulting RadDocument to the other format. Information on format providers can be found here.

3. When it comes to the formats, XAML is closest to the internal document model and provides practically lossless persistence. The other formats may have different limitations due to the lack of parallel between the model they have and the document model. For example, you can have headers, footers and comments in RadDocument, but they are not exported to HTML, because HTML has no such concept.

I hope this answers your questions!

Kind regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
John
Top achievements
Rank 2
Answers by
John
Top achievements
Rank 2
Iva Toteva
Telerik team
Share this question
or