C# 将XAML转换为HTML
我有来自富文本编辑器的XAML数据。我在XAML中的信息是关于HTML标记及其相关属性的。像段落,它的文本,样式等等,我想把它转换成HTML。XAML的一部分:C# 将XAML转换为HTML,c#,html,xaml,telerik,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.Docum
<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?因此,这里有一个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));
}
我们可以用同样的方法把苹果变成橘子。这没有道理,真的。但是我在XAML中得到的信息是关于HTML标记及其相关属性的。像段落,它的文字,风格等。请帮助。谢谢,我用这种方法,它的工作。