关于XAML代码的解析

bk7477890 2010-10-15 09:48:12
各位好

现有需求将RichTextbox的XAML属性产生的XAML代码转换为HTML代码

想听听各位有什么好的意见。


<Section xml:space="preserve" HasTrailingParagraphBreakOnPaste="False" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left"><Run FontSize="14" FontFamily="Courier New" Foreground="#FF000000" FontWeight="Bold" FontStyle="Italic" FontStretch="Normal" Text="ceshishuju_测试数据" /></Paragraph><Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left"><Run FontSize="14" FontFamily="Comic Sans MS" Foreground="#FF000000" FontWeight="Bold" FontStyle="Italic" FontStretch="Normal" Text="ceshishuju_测试数据" /></Paragraph><Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left"><Run FontSize="14" FontFamily="Courier New" Foreground="#FF0000FF" FontWeight="Normal" FontStyle="Italic" FontStretch="Normal" Text="ceshishuju_测试数据" /></Paragraph><Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left"><Run FontSize="14" FontFamily="Courier New" Foreground="#FFFF0000" FontWeight="Bold" FontStyle="Normal" FontStretch="Normal" Text="ceshishuju_测试数据" /></Paragraph><Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left"><Run FontSize="14" FontFamily="Arial" Foreground="#FF000000" FontWeight="Bold" FontStyle="Italic" FontStretch="Normal" Text="ceshishuju_测试数据" /></Paragraph><Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left"><Run FontSize="20" FontFamily="Courier New" Foreground="#FF000000" FontWeight="Bold" FontStyle="Italic" FontStretch="Normal" Text="ceshishuju_测试数据" /></Paragraph></Section>


例如这样的代码

转换成HTML


...全文
51 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bryht 2011-03-18
  • 打赏
  • 举报
回复
MSDN WPF XAML与HTML互换
bk7477890 2010-10-15
  • 打赏
  • 举报
回复
<Section xml:space="preserve" HasTrailingParagraphBreakOnPaste="False" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left">
<Run FontSize="14" FontFamily="Courier New" Foreground="#FF000000" FontWeight="Bold" FontStyle="Italic" FontStretch="Normal" Text="ceshishuju_测试数据" />
</Paragraph>
<Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left">
<Run FontSize="14" FontFamily="Comic Sans MS" Foreground="#FF000000" FontWeight="Bold" FontStyle="Italic" FontStretch="Normal" Text="ceshishuju_测试数据" />
</Paragraph>
<Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left">
<Run FontSize="14" FontFamily="Courier New" Foreground="#FF0000FF" FontWeight="Normal" FontStyle="Italic" FontStretch="Normal" Text="ceshishuju_测试数据" />
</Paragraph>
<Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left">
<Run FontSize="14" FontFamily="Courier New" Foreground="#FFFF0000" FontWeight="Bold" FontStyle="Normal" FontStretch="Normal" Text="ceshishuju_测试数据" />
</Paragraph>
<Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left">
<Run FontSize="14" FontFamily="Arial" Foreground="#FF000000" FontWeight="Bold" FontStyle="Italic" FontStretch="Normal" Text="ceshishuju_测试数据" />
</Paragraph>
<Paragraph FontSize="20" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left">
<Run FontSize="20" FontFamily="Courier New" Foreground="#FF000000" FontWeight="Bold" FontStyle="Italic" FontStretch="Normal" Text="ceshishuju_测试数据" />
</Paragraph>
</Section>

我换了一下行,这样看起来比较方便
0 大家都知道 XAML是“用来设计UI”的 设计师用XAML设计出来的UI其后台代码(程序逻辑)可以由程序员用C#或者VB去写 这叫做Code behind 实际上 设计师用XAML和程序用C#都是在构建同一个类 换句话说就是:把一个类劈成两半 与UI相关的那半由设计师用XAML写 与逻辑相关的那半由程序员用C#写 1 这个Name属性是非常重要的 如果你想在一棵“树”上查找叫某个名字的元素 调用“树根”的FindName方法就可以做到了 3 TextBox t this FindName "Made in China" as TextBox; 4 x:Name的x加一个冒号 说明它来自x这个名称空间 这个名称空间是定义在XAML的根元素上的 也就是这句: xmlns:x [url]http: schemas microsoft com winfx 2006 xaml[ url] 这个x就是XAML的字头了 这个名称空间的本意就是告诉我们 这个名称空间里所装的元素都与XAML解析有关 比如 我在代码里还使用了x:Code 把本来应该呆在C#代码里的内容请到XAML里来了 5 <Window x:Class < 只使用xaml编写一个窗体 >< 只使用一个单独的xaml文件 > namespace Cnblog{ 只使用Code Behind编写一个窗体 只使用一个单独的OnlyCo 6 XAML中x:Name和Name最终效果相同 XAML中使用Name其实被映射到了x:Name x:Name才是XAML中唯一的标识 所以它们效果相同 x:Name不是SomeWpfType Name 当我们设置了x:Name后(假设为ElementName XAML中x:Name与Name并不完全等价 不是所有类型都可以使用Name 但是任何类型都可以使用x:Name 只有拥有Name属性 才可以在XAML中使用Name 不同于x:Name 因为这个是附加属性 并且该类型 或者其父类型标记了RuntimeNameProperty特性 才拥有与x:Name一样的效果 例如:<SolidColorBrush Color "Transparent" Name "ddd" >便会报错 因为SolidColorBrush没有Name属性 只能使用x:Name <SolidColorBrush Color "Transparent" x:Name "ddd" > 1 分析为什么要有x:Name">0 大家都知道 XAML是“用来设计UI”的 设计师用XAML设计出来的UI其后台代码(程序逻辑)可以由程序员用C#或者VB去写 这叫做Code behind 实际上 设计师用XAML和程序用C#都是在构建同一个类 换句话说就是:把一个类劈成 [更多]

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧