资源简介
此代码是为实现html与xaml进行转换设计的!
代码片段和文件信息
//---------------------------------------------------------------------------
//
// File: HtmlXamlConverter.cs
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// Description: Prototype for Html - Xaml conversion
//
//---------------------------------------------------------------------------
namespace HTMLConverter
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows; // DependencyProperty
using System.Windows.Documents; // TextElement
using System.xml;
using System.xml.Linq;
///
/// HtmlToXamlConverter is a static class that takes an HTML string
/// and converts it into XAML
///
public static class HtmlToXamlConverter
{
// ---------------------------------------------------------------------
//
// Internal Methods
//
// ---------------------------------------------------------------------
#region Internal Methods
///
/// Converts an html string into xaml string.
///
///
/// Input html which may be badly formated xml.
///
///
/// true indicates that we need a FlowDocument as a root element;
/// false means that Section or Span elements will be used
/// dependeing on StartFragment/EndFragment comments locations.
///
///
/// Well-formed xml representing XAML equivalent for the input html string.
///
public static xmlElement ConvertHtmlToXaml(string htmlString bool asFlowDocument)
{
// Create well-formed xml from Html string
xmlElement htmlElement = HtmlParser.ParseHtml(htmlString);
return htmlElement;
// Decide what name to use as a root
string rootElementName = asFlowDocument ? HtmlToXamlConverter.Xaml_FlowDocument : HtmlToXamlConverter.Xaml_Section;
// Create an xmlDocument for generated xaml
xmlDocument xamlTree = new xmlDocument();
xmlElement xamlFlowDocumentElement = xamlTree.CreateElement(null rootElementName _xamlNamespace);
// Extract style definitions from all style elements in the document
Cssstylesheet stylesheet = new Cssstylesheet(htmlElement);
// Source context is a stack of all elements - ancestors of a parentElement
ListlElement> sourceContext = new ListlElement>(10);
// Clear fragment parent
InlineFragmentParentElement = null;
// convert root html element
AddBlock(xamlFlowDocumentElement htmlElement new Hashtable() style
- 上一篇:C#贪食蛇全能版
- 下一篇:工厂用来测试键盘好坏的的一个软件
相关资源
- 游戏商城网页项目C# ASP.NET Web .zip
- winform窗体中嵌入网页(DHTML代码和w
- 锐浪asp.net MVC html5报表显示
- 传智播客.NET笔记
- HTML、C#以及SQL Server学生信息管理系统
- html5+js二维码扫描asp.net),可通用其
- HTML5+JQUERY文件上传,手机浏览器兼容
-
Wpf 样式和模板含 fr
amework 4.5 aero2 - wpf界面切换特效
- ILSpy2.1 WPF 改进 批量保存xaml版代码
- C# 各版本 HtmlAgilityPack 类库 HtmlAgilit
- asp.net 网页静态化组件(shipingx-Stati
- c# 同时将图片和文字复制到剪贴版 (
- HTML压缩
- Word文件转Html文档目录
- html5 绘图以及 动画
- bbsharp bbcode 转html 写的很简洁
- MVC通过过滤器 实现输出前对html修改(
- MVC输出前对html修改
- 带Html编辑器CSkin.dll版本
- NHtmlFilter1.0过滤Html危险脚本 防止XSS攻
- Html文件上传控件(整理前台使用版)
- html5简单进度条效(progressbar)
- QQ聊天记录Mht转Html格式(附工具源码
- WPF中将矢量转换为XAML
- WinformHTMLEditor winform 富文本编辑器
- 纯HTML弹出必填信息(popHint)
- C#读取HTML文件并插入到数据库
- C#实现WebSocket源码c#写的服务端html写的
- Web网页控制摄像头
评论
共有 条评论