将XAML转换为HTML

时间:2016-06-03 09:43:22

标签: c# html xaml telerik

我有来自富文本编辑器的XAML数据。我在XAML中的信息是关于HTML标记及其相关属性。像段落,它的文本,样式等我想将其转换为HTML。 XAML的一部分:

<t:RadDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:t="clr-namespace:Telerik.Windows.Documents.Model;assembly=Telerik.Windows.Documents" xmlns:s="clr-namespace:Telerik.Windows.Documents.Model.Styles;assembly=Telerik.Windows.Documents" version="1.2" LayoutMode="Flow" LineSpacing="1.15" LineSpacingType="Auto" ParagraphDefaultSpacingAfter="12" ParagraphDefaultSpacingBefore="0" SectionDefaultPageSize="816,1056" StyleName="defaultDocumentStyle">
  <t:RadDocument.ProtectionSettings>
<t:DocumentProtectionSettings EnableDocumentProtection="False" Enforce="False" HashingAlgorithm="None" HashingSpinCount="0" ProtectionMode="ReadOnly" />
  </t:RadDocument.ProtectionSettings>
  <t:RadDocument.Styles>
    <s:StyleDefinition DisplayName="Document Default Style" IsCustom="False" IsDefault="False" IsPrimary="True" Name="defaultDocumentStyle" Type="Default">
      <s:StyleDefinition.ParagraphStyle>
        <s:ParagraphProperties LineSpacing="1.15" SpacingAfter="12" />
      </s:StyleDefinition.ParagraphStyle>
      <s:StyleDefinition.SpanStyle>
        <s:SpanProperties FontFamily="Verdana" FontSize="16" FontStyle="Normal" FontWeight="Normal" />
      </s:StyleDefinition.SpanStyle>
    </s:StyleDefinition>
    <s:StyleDefinition DisplayName="TableNormal" IsCustom="False" IsDefault="True" IsPrimary="True" Name="TableNormal" Type="Table" />
  </t:RadDocument.Styles>
  <t:Section>
    <t:Paragraph Background="#00FFFFFF" FirstLineIndent="0" LeftIndent="0" LineSpacing="1.14999997615814" LineSpacingType="Auto" RightIndent="0" SpacingAfter="0" SpacingBefore="0" TextAlignment="Center">
      <t:Span FontWeight="Bold" Text="PATIENT REPORT" UnderlineDecoration="Line" />
    </t:Paragraph>
  </t:Section>
</t:RadDocument>

如何将其转换为HTML?

1 个答案:

答案 0 :(得分:0)

所以你有一个RadDocument。

您可以使用Telerik工具轻松将其转换为HTML:

public string ConvertToHtml(RadDocument doc)
{
    return new HtmlFormatProvider().Export(doc);
}

或者,如果你的xaml以字符串形式存在,你可以这样做:

public string ConvertXamlToHtml(string xamlString)
{
    return new HtmlFormatProvider().Export(new XamlFormatProvider().Import(xamlString));   
}