This is a migrated thread and some comments may be shown as answers.

Is there any advantage to using the XAML Format Provider?

3 Answers 222 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 19 Jul 2011, 03:31 AM
Hi,

At the moment I have a Silverlight application using your XAML format provider (I wrote this before you brought in some more format providers) and I am wondering if there is any advantage to me sticking with this provider when I would get more interoperability out of say the HTML provider.

My scenario is that 99% of my work is done in Silverlight.  But I need to support SEO which means I need to export my content as HTML.  I could either scrap using the XAML provider and go strictly with HTML, or I could go to the effort of writing a XSLT template and stripping out all of the extraneous metadata and simply output the raw content.  (I don't want to have the client do the conversion itself)

So is there any advantage to me using the XAML provider which has a proprietory format over something which is more interoperable?

Stephen

3 Answers, 1 is accepted

Sort by
0
Alex
Telerik team
answered on 21 Jul 2011, 01:32 PM
Hello Stephen,

XAML is indeed the preferred format when persisting documents created with RadRichTextBox as it most closely represents the underlining document model. Đ¢here are features of the rich text box that are simply not relevant in HTML format - for example headers and footers, page numbers etc. So if you start using HTML to store your documents you will loose some of the power of the rich text box.

Note that you can always convert form XAML to HTML if needed using the XAML and HTML format providers. This can be done on the client using Silverlight and/or on the server using the WPF controls in a desktop or ASP.NET context. So you can use this approach instead of XSLT templates.

Please let us know if you need further help.

Greetings,
Alex
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Stephen
Top achievements
Rank 1
answered on 24 Oct 2011, 11:43 PM
Hi,

I have tried your suggestion of having the web server perform the conversion.  This is the code I am currently using to convert from XAML to HTML using your WPF libraries:
XamlFormatProvider xamlProvider = new XamlFormatProvider();
RadDocument document = xamlProvider.Import(xaml);
//document.DocumentLayoutBox.BypassLayoutPolicies = true;
//document.DocumentLayoutBox.MeasureWithoutParentNotification = true;
HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
return htmlProvider.Export(document);

I get the following error:
System.TypeInitializationException was unhandled by user code
  Message=The type initializer for 'Telerik.Windows.Documents.Layout.RadTextMeasurerSL' threw an exception.
  Source=Telerik.Windows.Documents
  TypeName=Telerik.Windows.Documents.Layout.RadTextMeasurerSL
  StackTrace:
       at Telerik.Windows.Documents.Layout.RadTextMeasurerSL.Measure(String text, Span span)
       at Telerik.Windows.Documents.Layout.RadTextMeasurer.Measure(String text, Span span, SubStringPosition subStringPosition) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\RadTextMeasurer_WPF.cs:line 193
       at Telerik.Windows.Documents.Layout.SpanLayoutBox.MeasureOverride(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\SpanLayoutBox.cs:line 302
       at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\LayoutElement.cs:line 919
       at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\LayoutElement.cs:line 822
       at Telerik.Windows.Documents.Layout.ParagraphLayoutBox.MeasureOverride(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\ParagraphLayoutBox.cs:line 384
       at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\LayoutElement.cs:line 919
       at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\LayoutElement.cs:line 822
       at Telerik.Windows.Documents.Layout.SectionLayoutBox.MeasureOverrideInternal(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\SectionLayoutBox.cs:line 331
       at Telerik.Windows.Documents.Layout.SectionLayoutBox.MeasureOverride(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\SectionLayoutBox.cs:line 235
       at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\LayoutElement.cs:line 919
       at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\LayoutElement.cs:line 822
       at Telerik.Windows.Documents.Layout.DocumentLayoutBox.MeasureOverride(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\DocumentLayoutBox.cs:line 197
       at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\LayoutElement.cs:line 889
       at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\LayoutElement.cs:line 822
       at Telerik.Windows.Documents.Model.RadDocument.Measure(SizeF measureSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Model\RadDocument.cs:line 752
       at Telerik.Windows.Documents.Model.RadDocument.MeasureAndArrangeInDefaultSize() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Model\RadDocument.cs:line 2382
       at Telerik.Windows.Documents.FormatProviders.Html.Export.HtmlDocumentExporter.Export(RadDocument document, Stream output) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Telerik.Windows.Documents.FormatProviders.Html\Export\HtmlDocumentExporter.cs:line 56
       at Telerik.Windows.Documents.FormatProviders.Html.HtmlFormatProvider.Export(RadDocument document) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Telerik.Windows.Documents.FormatProviders.Html\HtmlFormatProvider.cs:line 81
** Call to Converter occurs here **
System.InvalidOperationException
       Message=The calling thread must be STA, because many UI components require this.
       Source=PresentationCore
       StackTrace:
            at System.Windows.Input.InputManager..ctor()
            at System.Windows.Input.InputManager.GetCurrentInputManagerImpl()
            at System.Windows.Input.KeyboardNavigation..ctor()
            at System.Windows.FrameworkElement.EnsureFrameworkServices()
            at System.Windows.FrameworkElement..ctor()
            at Telerik.Windows.Documents.Layout.RadTextMeasurerSL.InitializeMeasureBlock() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Layout\RadTextMeasurerSL_WPF.cs:line 52
       InnerException:

I would really rather not switch my services to using a Single Threaded Apartment model.  I've tried to look for ways to disable the arrangement of the document as I don't believe it matters, but I can't see anything obvious in the available properties or source code.  All I am after is the HTML version of the XAML.  Is there any way to do this outside of Silverlight / WPF?
0
Iva Toteva
Telerik team
answered on 25 Oct 2011, 02:35 PM
Hello Stephen,

The document needs to be measured and arranged after import, so that it can calculate its layout and properly export its content to HTML. However, importing a document and measuring it requires that some UI elements be created, which can only occur on a Thread in Single-Threaded apartment state. This is what causes the exception in RadTextMerasurerSL. Unfortunately, there is no other way to convert documents at this point, but to use a Thread in Single Threaded apartment state.

Regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Stephen
Top achievements
Rank 1
Answers by
Alex
Telerik team
Stephen
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or