Edit this page

MEF

RadRichTextBox uses the Managed Extensibility Framework (MEF) in order to provide customization options, such as creating and utilizing custom dialogs and pop-ups, format providers and dictionaries for spellchecking. It finds and loads the types from the assemblies and they can be used without being explicitly initialized.

Customization

MEF allows you to easily customize or even replace the extensible parts.

Dialogs, Selection Mini Toolbar and Context Menu

To plug a custom dialog and replace the default one you need to implement the corresponding interface and mark the class that implements it with an attribute. Example 1 shows how to replace the default InsertDateTimeDialog with a custom one. This will skip the default type and load the custom one. The same approach could be used to override the rest of the dialogs, the selection mini toolbar and the context menu.

[C#] Example 1: Create Custom Dialog

[CustomInsertDateTimeDialog]
public partial class CustomInsertDateTimeDialog: RadRichTextBoxWindow, IInsertDateTimeDialog 

You could find a complete example showing how to implement a custom InsertDateTimeDialog as well as other implementations of custom dialogs in the XAML SDK repository on GitHub.

Format Providers

New format providers can be easily plugged-in by deriving from the DocumentFormatProviderBase class or directly from a concrete existing provider and marking the class with the CustomDocumentFormatProviderAttribute

[C#] Example 2: Create Custom Format Provider

[CustomDocumentFormatProvider]
public class DocFormatProvider : DocumentFormatProviderBase

An example showing how to create a custom format provider could be downloaded here.

Thanks to MEF you could replace the UILayersBuilder class as well, which is responsible for loading all the UI layers. More details about how to change this builder and what are UI layers can be found here.

Dictionaries

You can create and plug your custom dictionary by implementing the IWordDictionary interface. Example 3 demonstrates how to create a dictionary for Danish.

[C#] Example 3: Create Custom Dictionary

[WordDictionaryMetadata("da-DK")]
public class CustomDanishDictionary : IWordDictionary

Initial Load Performance of RadRichTextBox

When RadRichTextBox is loaded, the MEF checks all the assemblies, which the control has dependencies to and loads the necessary parts using reflection. However, traversing all the assemblies and searching if there is something to load in them is a slow operation and may decrease the initial load performance of the control. Below are listed the possible approaches to speed up the loading of all necessary for the application types or just load them without using MEF.

Explicitly set the necessary types

You can define a new TypeCatalog with the necessary types and pass it to the Catalog property of RadCompositionInitializer on application start-up before the RadRichTextBox is instantiated. In this scenario, the MEF will know exactly which types to load and won’t search for other ones. Example 4 shows the full TypeCatalog for the control.

[C#] Example 4: Create TypeCatalog

RadCompositionInitializer.Catalog = new TypeCatalog(
// format providers
typeof(XamlFormatProvider),
typeof(RtfFormatProvider),
typeof(DocxFormatProvider),
typeof(PdfFormatProvider),
typeof(HtmlFormatProvider),
typeof(TxtFormatProvider),

// mini toolbars
typeof(SelectionMiniToolBar),
typeof(ImageMiniToolBar),

// context menu
typeof(ContextMenu),

// the default English spellchecking dictionary
typeof(RadEn_USDictionary),

// dialogs
typeof(AddNewBibliographicSourceDialog),
typeof(ChangeEditingPermissionsDialog),
typeof(EditCustomDictionaryDialog),
typeof(FindReplaceDialog),
typeof(FloatingBlockPropertiesDialog),
typeof(FontPropertiesDialog),
typeof(ImageEditorDialog),
typeof(InsertCaptionDialog),
typeof(InsertCrossReferenceWindow),
typeof(InsertDateTimeDialog),
typeof(InsertTableDialog),
typeof(InsertTableOfContentsDialog),
typeof(ManageBibliographicSourcesDialog),
typeof(ManageBookmarksDialog),
typeof(ManageStylesDialog),
typeof(NotesDialog),
typeof(ProtectDocumentDialog),
typeof(RadInsertHyperlinkDialog),
typeof(RadInsertSymbolDialog),
typeof(RadParagraphPropertiesDialog),
typeof(SetNumberingValueDialog),
typeof(SpellCheckingDialog),
typeof(StyleFormattingPropertiesDialog),
typeof(TableBordersDialog),
typeof(TablePropertiesDialog),
typeof(TabStopsPropertiesDialog),
typeof(UnprotectDocumentDialog),
typeof(WatermarkSettingsDialog));

You could remove all the types you won’t need in your application.

The type catalog you set is going to be used from all instances of RadRichTextBox in the application.

Format Providers Loading

By default, RadRichTextBox loads all the format providers in the referenced assemblies. If you don’t need them all, you could turn off the MEF and register only the used providers. Example 5 demonstrates how to load only DocxFormatProvider, even if other format providers assemblies are added to the project .

[C#] Example 5: Load Format Provider

DocumentFormatProvidersManager.AutomaticallyLoadFormatProviders = false;
DocumentFormatProvidersManager.RegisterFormatProvider(new DocxFormatProvider());

UILayersBuilder Loading

The UILayersBuilder class is responsive for loading all the UI layers in the RadRichTextBox. The initialization of this type will load the layers without using MEF.

[C#] Example 6: Initialize UILayersBuilder

this.radRichTextBox.UILayersBuilder = new UILayersBuilder();

Spell Checking

All the dictionaries for the spell checking functionality are loaded with MEF. You could prevent this in two ways.

  • If the spell checking is not among the requirements for the application, you could turn it off.

    [C#] Example 7: Disable Spell Checking

        this.radRichTextBox.IsSpellCheckingEnabled = false;
    
  • In case you plan to use the built-in spell checker, you could tell the MEF to not search and load for all the default dictionaries and load manually only the ones which will be used in your application.

    [C#] Example 8: Use Spell Checking Without MEF

        this.radRichTextBox.IsSpellCheckingEnabled = true;
        DocumentSpellChecker documentSpellChecker = this.radRichTextBox.SpellChecker as DocumentSpellChecker;
        documentSpellChecker.AutomaticallyLoadDefaultDictionaries = false;
    

See also