6

 
 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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.

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

We create a New Project.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

We call it TelerikNoteTaker.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

We add a table.

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

We add a NoteTaker_People table with the schema above

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

We add a Screen.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

We create a List and Details Screen.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

The Screen will show.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

We click on the List Column

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

We set the Properties according to the image above.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

We hit F5 to run the application.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

Create a New Project.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

Create a Silverlight Class Library called SilverlightControls.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

Make it Silverlight 4 (or higher).

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

Delete the Class1.cs file that is automatically created.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

Add a New Item.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

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

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

Click Finish.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

This will create the RadTextBox.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

…and click on it.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

This will add two rows to the page.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

We then make the following changes:

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

The design surface will now resemble the image above.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

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

The screen will resemble the image above.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

The XAML markup will resemble the image above.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

The screen will resemble the image above.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

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

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

Build the Solution.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

Click Change in the Properties for the Custom Control.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

Select Add Reference.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

Select the Projects tab and then select the SilverlightControls project.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

This will allow us to select the TelerikEditor control.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

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

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

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

Click Add Reference.

 

Using the Telerik Rich Text Editor In Visual Studio LightSwitch

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

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

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

 

相关文章:

  • 2021-10-06
  • 2021-11-25
  • 2022-02-13
  • 2021-06-02
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
猜你喜欢
  • 2021-08-25
  • 2022-12-23
  • 2021-08-19
  • 2021-09-28
  • 2021-10-30
  • 2021-07-31
相关资源
相似解决方案