資源簡介
此代碼是為實(shí)現(xiàn)html與xaml進(jìn)行轉(zhuǎn)換設(shè)計(jì)的!
代碼片段和文件信息
//---------------------------------------------------------------------------
//?
//?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#貪食蛇全能版
- 下一篇:工廠用來測試鍵盤好壞的的一個(gè)軟件
評(píng)論
共有 條評(píng)論