Using the Telerik Rich Text Editor In Visual Studio LightSwitch

AUG6

Written by: Michael Washington 
8/6/2011 8:38 PM  RssIcon

 
 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第1张图片

Note: You must have Visual Studio Professional (or higher) to complete this tutorial

Telerik has a differentiating LightSwitch control in their Rich Text Editor Control. It allows you to create compelling LightSwitch applications. It allows your end-users to create, import and export Microsoft Word documents. It also contains many other features.

In this example, we will build a small application that allows rich notes to be entered for people.

First, Install the Telerik controls for LightSwitch available here: http://www.telerik.com/products/lightswitch-support.aspx.

image

We create a New Project.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第2张图片

We call it TelerikNoteTaker.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第3张图片

We add a table.

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第4张图片

We add a NoteTaker_People table with the schema above

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第5张图片

We clear the length of the Notes field  (this sets it to unlimited) because the XAML markup is large.

We also un-check the Display As Default because we do not want it to display in the automatic popup that LightSwitch will create to allow us to edit the data in the table. We only want to edit the name not the notes in the automatic popup that LightSwitch creates.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第6张图片

We add a Screen.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第7张图片

We create a List and Details Screen.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第8张图片

The Screen will show.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第9张图片

We click on the List Column

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第10张图片

We set the Properties according to the image above.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第11张图片

We right-click on the Name column and Delete it (we can enter a name and edit it in the popup that will automatically be created)

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第12张图片

We hit F5 to run the application.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第13张图片

We enter some sample data.

We then close the application.

 

Create The Custom Control

While it is possible to directly implement any Silverlight control in LightSwitch (my book, Creating Visual Studio LightSwitch Custom Controls (Beginner to Intermediate), covers all the methods and the syntax to use), it is actually easer and requires less code, to simply create a Silverlight Custom Control (a .xamlpage), and then put the Silverlight control that you want to implement on that .xaml page.

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第14张图片

Create a New Project.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第15张图片

Create a Silverlight Class Library called SilverlightControls.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第16张图片

Make it Silverlight 4 (or higher).

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第17张图片

Delete the Class1.cs file that is automatically created.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第18张图片

Add the following references to the Silverlight project:

  • System.Windows.Browser.dll
  • Main Telerik Assemblies
    • Telerik.Windows.Controls.dll
    • Telerik.Windows.Controls.ImageEditor.dll
    • Telerik.Windows.Controls.Input.dll
    • Telerik.Windows.Controls.Navigation.dll
    • Telerik.Windows.Controls.RibbonBar.dll
    • Telerik.Windows.Controls.RichTextBoxUI.dll
    • Telerik.Windows.Data.dll
    • Telerik.Windows.Documents.dll
  • Format providers for export/import
    • Telerik.Windows.Documents.FormatProviders.Html.dll
    • Telerik.Windows.Documents.FormatProviders.MsRichTextBoxXaml.dll
    • Telerik.Windows.Documents.FormatProviders.OpenXml.dll
    • Telerik.Windows.Documents.FormatProviders.Pdf.dll
    • Telerik.Windows.Documents.FormatProviders.Rtf.dll
    • Telerik.Windows.Documents.FormatProviders.Xaml.dll
  • Spell Checking
    • Telerik.Windows.Documents.Proofing.dll
    • Telerik.Windows.Documents.Proofing.Dictionaries.En-US.dll

Note: Install the Telerik controls for LightSwitch here: http://www.telerik.com/products/lightswitch-support.aspx

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第19张图片

Add a New Item.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第20张图片

Add a new Silverlight control and name it TelerikEditor.xaml.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第21张图片

We change the DesignHeight to 600 x 800 and zoom out to 50%.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第22张图片

From the Visual Studio Toolbox, we drag the RadRichTextBox control, and drop it on the design surface.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第23张图片

A configuration wizard will show.

We choose Text Box or Rich Text Box. This option will allow us to select a DataProvider needed to allow us to save data in LightSwitch.

The way the RadRichTextBox control works, is that it simply shows data supplied by the DataProvider that is attached to it. This allows the same control to show XAML (viewable in Silverlight and WPF), HTML (viewable on a normal web page), RTF (Microsoft Word format), or plan Text.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第24张图片

The next screen will allow us to select the DataProvider.

In this example we will choose XAMLDataProvider because the content will only be shown in Silverlight. If we wanted to show the content on a regular web page we would choose the HTMLDataProvder.

For a full discussion of DataProviders see:

http://www.telerik.com/help/silverlight/radrichtextbox-features-data-providers.html

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第25张图片

Click Finish.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第26张图片

This will create the RadTextBox.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第27张图片

We then hover the mouse on the left-side blue bar…

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第28张图片

…and click on it.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第29张图片

This will add two rows to the page.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第30张图片

If we look at the XAML markup for the RadRichTextBox control, it will resemble the image above.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第31张图片

We then make the following changes:

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第32张图片

The design surface will now resemble the image above.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第33张图片

From the Visual Studio Toolbox, we drag the RadRichTextBoxRibbonUI control and drop it on the design surface.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第34张图片

You will see a box pop up while the Telerik control generates the XAML markup.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第35张图片

The screen will resemble the image above.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第36张图片

The XAML markup will resemble the image above.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第37张图片

Change the XAML markup to resemble the image above.

  • Remove the Height and Width settings
  • Set the Margins to 0

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第38张图片

The screen will resemble the image above.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第39张图片

You will note that if you click on the Ribbon Bar control in the Visual Studio editor, additional configuration buttons will appear.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第40张图片

Each configuration button will display a menu that allows additional configuration.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第41张图片

Build the Solution.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第42张图片

In the LightSwitch screen editor, change the Notes TextBox to a Custom Control.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第43张图片

Click Change in the Properties for the Custom Control.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第44张图片

Select Add Reference.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第45张图片

Select the Projects tab and then select the SilverlightControls project.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第46张图片

This will allow us to select the TelerikEditor control.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第47张图片

In the Properties for the Custom Control, set the Label Position to None and the MinHeight to 600.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第48张图片

If you try to run the project at this point, you will get an error.

The Telerik assemblies (the .dll’s) need to be added to the LightSwitch project.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第49张图片

In the Properties for the Custom Control, click Change again.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第50张图片

Click Add Reference.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第51张图片

We select the .Net tab, and we add the references we added earlier and click the OK button.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第52张图片

Click Cancel on the Add Custom Control box (we did not want to change any configuration on the custom control, we only wanted to add references) .

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch_第53张图片

When we run the application, we now have a full featured rich text editor that allows us to open and save Microsoft Word documents and even has undo and redo buttons.

 

Download Code

The LightSwitch project is available at http://lightswitchhelpwebsite.com/Downloads.aspx

 

你可能感兴趣的:(switch)