XAML 服務XAML Services

本主題說明稱為 .NET XAML 服務的技術集的功能。This topic describes the capabilities of a technology set known as .NET XAML Services. 大部分所述的服務和 Api 都位於元件中 System.XamlThe majority of the services and APIs described are located in the assembly System.Xaml. 服務包括讀取器和寫入器、架構類別和架構支援、factory、類別的類化、XAML 語言內建支援,以及其他 XAML 語言功能。Services include readers and writers, schema classes and schema support, factories, attributing of classes, XAML language intrinsic support, and other XAML language features.

關於此檔About This Documentation

.NET XAML 服務的概念檔假設您先前已有 XAML 語言的經驗,以及它如何套用至特定的架構,例如 Windows Presentation Foundation (WPF) 或 Windows Workflow Foundation,或特定的技術功能區,例如中的組建自訂功能 Microsoft.Build.Framework.XamlTypesConceptual documentation for .NET XAML Services assumes that you have previous experience with the XAML language and how it might apply to a specific framework, for example Windows Presentation Foundation (WPF) or Windows Workflow Foundation, or a specific technology feature area, for example the build customization features in Microsoft.Build.Framework.XamlTypes. 這份檔不會嘗試將 XAML 的基本概念解釋為標記語言、XAML 語法術語或其他簡介材質。This documentation does not attempt to explain the basics of XAML as a markup language, XAML syntax terminology, or other introductory material. 相反地,本檔著重于特別使用在 System.object 元件庫中啟用的 .NET XAML 服務。Instead, this documentation focuses on specifically using .NET XAML Services that are enabled in the System.Xaml assembly library. 這些 Api 大多適用于 XAML 語言整合和擴充性的案例。Most of these APIs are for scenarios of XAML language integration and extensibility. 這可能包括下列任何案例:This might include any of the following scenarios:

  • 擴充基底 XAML 讀取器或 XAML 寫入器的功能, (直接處理 XAML 節點資料流程;將您自己的 XAML 讀取器或 XAML 寫入器) 。Extending the capabilities of the base XAML readers or XAML writers (processing the XAML node stream directly; deriving your own XAML reader or XAML writer).

  • 定義無特定架構相依性的 XAML 可用自訂類型,並將型別預先定義為將其 XAML 類型系統特性傳遞給 .NET XAML 服務。Defining XAML-usable custom types that do not have specific framework dependencies, and attributing the types to convey their XAML type system characteristics to .NET XAML Services.

  • 將 XAML 讀取器或 XAML 寫入器裝載為應用程式的元件,例如視覺化設計工具或 XAML 標記來源的互動式編輯器。Hosting XAML readers or XAML writers as a component of an application, such as a visual designer or interactive editor for XAML markup sources.

  • 撰寫 XAML 值轉換器 (標記延伸;自訂類型) 的類型轉換器。Writing XAML value converters (markup extensions; type converters for custom types).

  • 使用支援類型來源的替代元件載入技術來定義自訂 XAML 架構內容 (;使用已知型別查閱技術,而不是一律反映元件;使用載入的元件概念,這些概念不會使用 common language runtime (CLR) 與其 AppDomain 相關聯的安全性模型) 。Defining a custom XAML schema context (using alternate assembly-loading techniques for backing type sources; using known-types lookup techniques instead of always reflecting assemblies; using loaded assembly concepts that do not use the common language runtime (CLR) AppDomain and its associated security model).

  • 擴充基底 XAML 型別系統。Extending the base XAML type system.

  • 使用 LookupInvoker 技術來影響 XAML 型別系統,以及如何評估型別 backings。Using the Lookup or Invoker techniques to influence the XAML type system and how type backings are evaluated.

如果您要以語言尋找 XAML 的簡介資料,您可能會嘗試 (WPF) 的 Xaml 總覽 If you are looking for introductory material on XAML as a language, you might try XAML Overview (WPF). 該主題討論 XAML,以瞭解 Windows Presentation Foundation (WPF) 以及使用 XAML 標記和 XAML 語言功能的新物件。That topic discusses XAML for an audience that is new both to Windows Presentation Foundation (WPF) and also to using XAML markup and XAML language features. 另一個實用的檔是 XAML 語言規格中的簡介資料。Another useful document is the introductory material in the XAML language specification.

.NET XAML 服務和 System.Xaml .Net 架構.NET XAML Services and System.Xaml in the .NET Architecture

.NET XAML 服務和 System.Xaml 元件會定義支援 XAML 語言功能所需的大部分功能。.NET XAML Services and the System.Xaml assembly define much of what is needed for supporting XAML language features. 這包括 XAML 讀取器和 XAML 寫入器的基類。This includes base classes for XAML readers and XAML writers. 新增至 .NET XAML 服務的最重要功能(不存在於任何架構特定的 XAML 執行)是 XAML 的型別系統標記法。The most important feature added to .NET XAML Services that was not present in any of the framework-specific XAML implementations is a type system representation for XAML. 型別系統表示以物件導向的方式呈現 XAML,而不需要依賴 framework 的特定功能。The type system representation presents XAML in an object-oriented way that centers on XAML capabilities without taking dependencies on specific capabilities of frameworks.

XAML 類型系統不受限於 XAML 來源的標記表單或執行時間細節;也不受限於任何特定的支援類型系統。The XAML type system is not limited by the markup form or run-time specifics of the XAML origin; nor is it limited by any specific backing type system. XAML 類型系統包含類型、成員、XAML 架構內容、XML 層級概念,以及其他 XAML 語言概念或 XAML 內建函式的物件標記法。The XAML type system includes object representations for types, members, XAML schema contexts, XML-level concepts, and other XAML language concepts or XAML intrinsics. 使用或擴充 XAML 型別系統可衍生自 XAML 讀取器和 XAML 寫入器等類別,並將 XAML 表示的功能擴充至架構、技術或取用或發出 XAML 的應用程式所啟用的特定功能。Using or extending the XAML type system makes it possible to derive from classes like XAML readers and XAML writers, and extend the functionality of XAML representations into specific features enabled by a framework, a technology, or an application that consumes or emits XAML. XAML 架構內容的概念可讓 XAML 物件寫入器執行的組合、技術的支援類型系統(透過內容中的元件資訊和 XAML 節點來源)進行通訊,以實現實際的物件圖形寫入作業。The concept of a XAML schema context enables practical object graph write operations from the combination of a XAML object writer implementation, a technology's backing type system as communicated through assembly information in the context, and the XAML node source. 如需 XAML 架構概念的詳細資訊。For more information on the XAML schema concept. 請參閱 預設 XAML 架構內容和 WPF XAML 架構內容see Default XAML Schema Context and WPF XAML Schema Context.

XAML 節點資料流程、XAML 讀取器和 XAML 寫入器XAML Node Streams, XAML Readers, and XAML Writers

若要瞭解 .NET XAML 服務在 XAML 語言和使用 XAML 做為語言的特定技術之間的關係中扮演的角色,瞭解 XAML 節點資料流程的概念,以及該概念如何將 API 和術語組成概念,是很有説明的。To understand the role that .NET XAML Services plays in the relationship between the XAML language and specific technologies that use XAML as a language, it is helpful to understand the concept of a XAML node stream and how that concept shapes the API and terminology. XAML 節點資料流程是 xaml 語言表示與 XAML 代表或定義的物件圖形之間的概念中繼。The XAML node stream is a conceptual intermediate between a XAML language representation and the object graph that the XAML represents or defines.

  • XAML 讀取器是以某種形式處理 XAML,並產生 XAML 節點資料流程的實體。A XAML reader is an entity that processes XAML in some form, and produces a XAML node stream. 在 API 中,XAML 讀取器是以基類表示 XamlReaderIn the API, a XAML reader is represented by the base class XamlReader.

  • XAML 寫入器是處理 XAML 節點資料流程並產生其他內容的實體。A XAML writer is an entity that processes a XAML node stream and produces something else. 在 API 中,XAML 寫入器是由基類表示 XamlWriterIn the API, a XAML writer is represented by the base class XamlWriter.

    關於 XAML 的兩個最常見案例是載入 XAML 來具現化物件圖形,並從應用程式或工具儲存物件圖形,並產生 XAML 標記法, (通常會以儲存為文字檔的標記形式儲存) 。The two most common scenarios involving XAML are loading XAML to instantiate an object graph, and saving an object graph from an application or tool and producing a XAML representation (typically in markup form saved as text file). 在此檔中,載入 XAML 和建立物件圖形通常稱為載入路徑。Loading XAML and creating an object graph is often referred to in this documentation as the load path. 在此檔中,將現有的物件圖形儲存或序列化為 XAML 通常稱為儲存路徑。Saving or serializing an existing object graph to XAML is often referred to in this documentation as the save path.

    最常見的載入路徑類型可以描述如下:The most common type of load path can be described as follows:

  • 以 UTF 編碼 XML 格式的 XAML 標記法開始,並儲存為文字檔。Start with a XAML representation, in UTF-encoded XML format and saved as a text file.

  • 將 XAML 載入至 XamlXmlReaderLoad that XAML into XamlXmlReader. XamlXmlReader 是子 XamlReader 類別。XamlXmlReader is a XamlReader subclass.

  • 結果是 XAML 節點資料流程。The result is a XAML node stream. 您可以使用 API 來存取 XAML 節點資料流程的個別節點 XamlXmlReader / XamlReaderYou can access individual nodes of the XAML node stream using XamlXmlReader / XamlReader API. 最常見的作業是前進到 XAML 節點資料流程,使用「目前的記錄」比喻來處理每個節點。The most typical operation here is to advance through the XAML node stream, processing each node using a "current record" metaphor.

  • 將產生的節點從 XAML 節點資料流程傳遞至 XamlObjectWriter API。Pass the resulting nodes from the XAML node stream to a XamlObjectWriter API. XamlObjectWriter 是子 XamlWriter 類別。XamlObjectWriter is a XamlWriter subclass.

  • XamlObjectWriter 根據來源 XAML 節點資料流程的進度,寫入物件圖形(一次一個物件)。The XamlObjectWriter writes an object graph, one object at a time, in accordance to progress through the source XAML node stream. 物件寫入是透過 XAML 架構內容的協助,以及可存取支援類型系統和架構之元件和類型的實作為來完成。Object writing is done with the assistance of a XAML schema context and an implementation that can access the assemblies and types of a backing type system and framework.

  • Result在 XAML 節點資料流程的結尾呼叫,以取得物件圖形的根物件。Call Result at the end of the XAML node stream to obtain the root object of the object graph.

    最常見的儲存路徑類型可以描述如下:The most common type of save path can be described as follows:

  • 從整個應用程式執行時間的物件圖形、執行時間的 UI 內容和狀態,或在執行時間之整體應用程式物件表示的較社區段開始。Start with the object graph of an entire application run time, the UI content and state of a run time, or a smaller segment of an overall application's object representation at run time.

  • 從邏輯啟始物件(例如應用程式根目錄或檔根目錄)將物件載入至 XamlObjectReaderFrom a logical start object, such as an application root or document root, load the objects into XamlObjectReader. XamlObjectReader 是子 XamlReader 類別。XamlObjectReader is a XamlReader subclass.

  • 結果是 XAML 節點資料流程。The result is a XAML node stream. 您可以使用和 API 來存取 XAML 節點資料流程的個別節點 XamlObjectReader XamlReaderYou can access individual nodes of the XAML node stream using XamlObjectReader and XamlReader API. 最常見的作業是前進到 XAML 節點資料流程,使用「目前的記錄」比喻來處理每個節點。The most typical operation here is to advance through the XAML node stream, processing each node using a "current record" metaphor.

  • 將產生的節點從 XAML 節點資料流程傳遞至 XamlXmlWriter API。Pass the resulting nodes from the XAML node stream to a XamlXmlWriter API. XamlXmlWriter 是子 XamlWriter 類別。XamlXmlWriter is a XamlWriter subclass.

  • XamlXmlWriter 以 XML UTF 編碼方式寫入 XAML。The XamlXmlWriter writes XAML in an XML UTF encoding. 您可以將它儲存為文字檔、資料流程或其他表單。You can save this as a text file, as a stream, or in other forms.

  • 呼叫 Flush 以取得最終輸出。Call Flush to obtain the final output.

如需 XAML 節點資料流程概念的詳細資訊,請參閱 瞭解 Xaml 節點資料流程結構和概念For more information about XAML node stream concepts, see Understanding XAML Node Stream Structures and Concepts.

XamlServices 類別The XamlServices Class

不一定需要處理 XAML 節點資料流程。It is not always necessary to deal with a XAML node stream. 如果您想要基本的載入路徑或基本的儲存路徑,可以使用類別中的 Api XamlServicesIf you want a basic load path or a basic save path, you can use APIs in the XamlServices class.

  • 執行載入路徑的各種簽章 LoadVarious signatures of Load implement a load path. 您可以載入檔案或資料流程,也可以載入 XmlReaderTextReader 或載入 XamlReader 以包裝 XAML 輸入,方法是使用該讀取器的 api 進行載入。You can either load a file or stream, or can load an XmlReader, TextReader or XamlReader that wrap your XAML input by loading with that reader's APIs.

  • Save儲存物件圖形並以資料流程、檔案或實例形式產生輸出的各種簽章 XmlWriter / TextWriterVarious signatures of Save save an object graph and produce output as a stream, file, or XmlWriter/TextWriter instance.

  • Transform 藉由將載入路徑和儲存路徑連結為單一作業來轉換 XAML。Transform converts XAML by linking a load path and a save path as a single operation. 不同的架構內容或不同的支援類型系統可用於 XamlReaderXamlWriter ,這會影響產生的 XAML 轉換方式。A different schema context or different backing type system could be used for XamlReader and XamlWriter, which is what influences how the resulting XAML is transformed.

如需如何使用的詳細資訊 XamlServices ,請參閱 XAMLServices 類別和基本 XAML 讀取或寫入For more information about how to use XamlServices, see XAMLServices Class and Basic XAML Reading or Writing.

XAML 類型系統XAML Type System

XAML 型別系統提供使用 XAML 節點資料流程的特定個別節點所需的 Api。The XAML type system provides the APIs that are required to work with a given individual node of a XAML node stream.

XamlType 這是物件的標記法-開始物件節點和結束物件節點之間的處理。XamlType is the representation for an object - what you are processing between a start object node and end object node.

XamlMember 這是物件成員的標記法-開始成員節點和結束成員節點之間的處理。XamlMember is the representation for a member of an object - what you are processing between a start member node and end member node.

Api (例如 GetAllMembers 和)會 GetMember DeclaringType 報告和之間的關聯性 XamlType XamlMemberAPIs such as GetAllMembers and GetMember and DeclaringType report the relationships between a XamlType and XamlMember.

.NET XAML 服務所執行之 XAML 類型系統的預設行為是以 common language runtime (CLR) ,以及使用反映在元件中的 CLR 類型靜態分析為基礎。The default behavior of the XAML type system as implemented by .NET XAML Services is based on the common language runtime (CLR), and static analysis of CLR types in assemblies by using reflection. 因此,針對特定的 CLR 型別,XAML 型別系統的預設實值可以公開該型別的 XAML 架構和其成員,並根據 XAML 型別系統來報告它。Therefore, for a specific CLR type, the default implementation of the XAML type system can expose the XAML schema of that type and its members and report it in terms of the XAML type system. 在預設的 XAML 型別系統中,型別 xaml 的概念會對應到 CLR 繼承,而實例、實值型別等的概念也會對應到 CLR 的支援行為和功能。In the default XAML type system, the concept of assignability of types is mapped onto CLR inheritance, and the concepts of instances, value types, and so on, are also mapped to the supporting behaviors and features of the CLR.

XAML 語言功能的參考Reference for XAML Language Features

為了支援 XAML,.NET XAML 服務提供 xaml 語言概念的特定實作為 xaml 語言 XAML 命名空間的定義。To support XAML, .NET XAML Services provides specific implementation of XAML language concepts as defined for the XAML language XAML namespace. 這些會記載為特定參考頁面。These are documented as specific reference pages. 語言功能的記錄方式,是由 .NET XAML 服務所定義的 XAML 讀取器或 XAML 寫入器處理這些語言功能時的行為。The language features are documented from the perspective of how these language features behave when they are processed by a XAML reader or XAML writer that is defined by .NET XAML Services. 如需詳細資訊,請參閱 XAML Namespace (x:) Language FeaturesFor more information, see XAML Namespace (x:) Language Features.