New to Telerik UI for WinForms? Download free 30-day trial

Settings

XamlFormatProvider allows for import of XAML documents and respectively export of RadRichTextEditor to XAML file. Additionally, the import/export settings provide modification options. The current article outlines the available settings.

Since R2 2023 SP1 the XamlFormatProvider automatically verifies the imported XAML. More information is available in the Xaml Verification article.

Export Settings

XamlFormatProvider exposes ExportSettings, which allow you to control the export of the RadRichTextEditor document.

Export Settings Properties

  • ImageExportMode: A property of type ImageExportMode that gets or sets how the image should be exported. This property is an enumeration and it allows the following values:
    • None: Images are not exported.
    • RawData: Images are exported using their RawData.
    • ImageExportingEvent: Event is fired on exporting.
    • UriSource: The UriSource property is used instead of RawData. Bare in mind that this property may not be set on all images.

Export Settings Events

  • ImageExporting: This event is fired every time before exporting an Image.
  • InlineUIContainerExporting: This event is fired every time before exporting an InlineUIContainer.

These events will be called when the ImageExportMode enumeration property is set to ImageExportingEvent.

Setting the ExportSettings of the XamlFormatProvider

XamlFormatProvider xamlFormatProvider = new XamlFormatProvider();
XamlExportSettings settings = new XamlExportSettings();
settings.ImageExportMode = ImageExportMode.UriSource;
xamlFormatProvider.ExportSettings = settings;

Dim xamlFormatProvider As XamlFormatProvider = New XamlFormatProvider()
Dim settings As XamlExportSettings = New XamlExportSettings()
settings.ImageExportMode = ImageExportMode.UriSource
xamlFormatProvider.ExportSettings = settings

{{endregion}}

Import Settings

XamlFormatProvider exposes ImportSettings, which allow you to control the import of the XAML file.

Import Settings Events

  • ImageImported: This event is fired every time when the Image is imported.
  • InlineUIContainerImported: This event is fired every time when the InlineUIContainer is imported.
  • PreProcessingXaml: This event is fired right before the XAML is parsed and allows you to check it for undesired content. The event arguments expose the following options:
    • Xaml: The XAML string that is being imported. You can changed it and then pass it again to the property so the changed XAML is imported.
    • SkipXamlValidation: Allows you to skip the default XAML types validation.

Disable the default XAML validation__

{{source=..\SamplesCS\RichTextEditor\ImportExport\XamlFormatProviderForm.cs region=SkipVerification}} {{source=..\SamplesVB\RichTextEditor\ImportExport\XamlFormatProviderForm.vb region=SkipVerification}}


XamlFormatProvider provider = new XamlFormatProvider();
provider.ImportSettings.PreProcessingXaml += (s, args) => {

    args.SkipXamlValidation = true;
};


Dim provider As XamlFormatProvider = New XamlFormatProvider()
AddHandler provider.ImportSettings.PreProcessingXaml, Function(s, args)
                                                          args.SkipXamlValidation = True
                                                      End Function

}

Setting the ImportSettings of the XamlFormatProvider

XamlFormatProvider xamlFormatProvider = new XamlFormatProvider();
XamlImportSettings settings = new XamlImportSettings();
xamlFormatProvider.ImportSettings = settings;
settings.ImageImported += XamlImportSettings_ImageImported;

Dim xamlFormatProvider As XamlFormatProvider = New XamlFormatProvider()
Dim settings As XamlImportSettings = New XamlImportSettings()
xamlFormatProvider.ImportSettings = settings
AddHandler settings.ImageImported, AddressOf XamlImportSettings_ImageImported

ImageImported Event


private void XamlImportSettings_ImageImported(object sender, ImageImportedEventArgs e)
{
    var img = e.Image;
}


Private Sub XamlImportSettings_ImageImported(ByVal sender As Object, ByVal e As ImageImportedEventArgs)
    Dim img = e.Image
End Sub

See Also

In this article