zoukankan      html  css  js  c++  java
  • Using the Telerik Rich Text Editor In Visual Studio LightSwitch

    AUG6

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

     
     

    image

    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.

    image

    We call it TelerikNoteTaker.

    image

    We add a table.

    image

    We add a NoteTaker_People table with the schema above

    image

    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.

    image

    We add a Screen.

    image

    We create a List and Details Screen.

    image

    The Screen will show.

    image

    We click on the List Column

    image

    We set the Properties according to the image above.

    image

    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)

    image

    We hit F5 to run the application.

    image

    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.

    image

    Create a New Project.

    image

    Create a Silverlight Class Library called SilverlightControls.

    image

    Make it Silverlight 4 (or higher).

    image

    Delete the Class1.cs file that is automatically created.

    image

    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

    image

    Add a New Item.

    image

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

    image

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

    image

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

    image

    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.

    image

    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

    image

    Click Finish.

    image

    This will create the RadTextBox.

    image

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

    image

    …and click on it.

    image

    This will add two rows to the page.

    image

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

    image

    We then make the following changes:

    image

    The design surface will now resemble the image above.

    image

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

    image

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

    image

    The screen will resemble the image above.

    image

    The XAML markup will resemble the image above.

    image

    Change the XAML markup to resemble the image above.

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

    image

    The screen will resemble the image above.

    image

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

    image

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

    image

    Build the Solution.

    image

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

    image

    Click Change in the Properties for the Custom Control.

    image

    Select Add Reference.

    image

    Select the Projects tab and then select the SilverlightControls project.

    image

    This will allow us to select the TelerikEditor control.

    image

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

    image

    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.

    image

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

    image

    Click Add Reference.

    image

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

    image

    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) .

    image

    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

  • 相关阅读:
    .dll .h .lib等文件的作用与区别
    [转自]语言黑客的福音
    [转载]一个台湾程序员的心历路程
    Servlet学习总结
    会话跟踪(Cookie & Session)
    JSP学习总结
    人往高处走,水往低处流
    GDI 和GDI+ 混合编程
    常用到的知识
    Sqlite3相关
  • 原文地址:https://www.cnblogs.com/Areas/p/2791258.html
Copyright © 2011-2022 走看看