從 WPF 移轉至 System.Xaml 的類型Types Migrated from WPF to System.Xaml

在 .NET Framework 3.5 和 .NET Framework 3.0 中, Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF)和 Windows Workflow Foundation 都包含 XAML 語言執行。In .NET Framework 3.5 and .NET Framework 3.0, both Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) and Windows Workflow Foundation included a XAML language implementation. 有許多為 WPF XAML 實作提供擴充性的公用類型,存在於 WindowsBase、PresentationCore 和 PresentationFramework 組件中。Many of the public types that provided extensibility for the WPF XAML implementation existed in the WindowsBase, PresentationCore, and PresentationFramework assemblies. 同樣地, 為 Windows Workflow Foundation XAML 提供擴充性的公用類型也存在於 System.workflow.componentmodel.activity 元件中。Likewise, public types that provided extensibility for Windows Workflow Foundation XAML existed in the System.Workflow.ComponentModel assembly. 在 .NET Framework 4 中, 某些與 XAML 相關的類型會遷移至 system.string 元件。In the .NET Framework 4, some of the XAML-related types are migrated to the System.Xaml assembly. XAML 語言服務的常見 .NET Framework 執行, 可讓許多 XAML 擴充性案例原本是由特定架構的 XAML 執行所定義, 但現在已成為整體 .NET Framework 4 個 XAML 語言支援的一部分。A common .NET Framework implementation of XAML language services enables many XAML extensibility scenarios that were originally defined by a specific framework's XAML implementation but are now part of overall .NET Framework 4 XAML language support. 本主題會列出移轉的類型,並討論與移轉相關的問題。This topic lists the types that are migrated and discusses issues related to the migration.

組件和命名空間Assemblies and Namespaces

在 .NET Framework 3.5 和 .NET Framework 3.0 中, WPF 實作為支援 XAML 的類型通常是在System.Windows.Markup命名空間中。In .NET Framework 3.5 and .NET Framework 3.0, the types that WPF implemented to support XAML were generally in the System.Windows.Markup namespace. 這些類型大多數位於 WindowsBase 組件中。Most of these types were in the WindowsBase assembly.

在 .NET Framework 4 中, 有一個新System.Xaml的命名空間和一個新的 system.object 元件。In .NET Framework 4, there is a new System.Xaml namespace and a new System.Xaml assembly. 許多原先針對 WPF XAML 實作的類型,現已提供為任何 XAML 實作的擴充點或服務。Many of the types that were originally implemented for WPF XAML are now provided as extensibility points or services for any implementation of XAML. 為了可供更多一般情節使用,這些類型已從其原始 WPF 組件類型轉送至 System.Xaml 組件。As part of making them available for more general scenarios, the types are type-forwarded from their original WPF assembly to the System.Xaml assembly. 這會啟用 XAML 擴充性案例, 而不需要包含其他架構的元件 (例如 WPF 和 Windows Workflow Foundation)。This enables XAML extensibility scenarios without having to include the assemblies of other frameworks (such as WPF and Windows Workflow Foundation).

大部分移轉後的類型仍會位於 System.Windows.Markup 命名空間中。For migrated types, most of the types remain in the System.Windows.Markup namespace. 部分原因是為了避免破壞個別檔案之現有實作中的 CLR 命名空間對應。This was partially to avoid breaking CLR namespace mappings in existing implementations on a per-file basis. 因此, .NET Framework 4 中System.Windows.Markup的命名空間包含一般 XAML 語言支援類型的混合 (來自 system.string 元件), 以及 WPF XAML 實作為特定的類型 (來自 WindowsBase 和其他 wpf 元件)。As a result, the System.Windows.Markup namespace in .NET Framework 4 contains a mixture of general XAML language support types (from the System.Xaml assembly) and types that are specific to the WPF XAML implementation (from WindowsBase and other WPF assemblies). 任何已移轉至 System.Xaml、但先前存在於 WPF 組件中的類型,在 WPF 組件第 4 版中都具有類型轉送支援。Any type that was migrated to System.Xaml, but existed previously in a WPF assembly, has type-forwarding support in version 4 of the WPF assembly.

Workflow XAML 支援類型Workflow XAML Support Types

Windows Workflow Foundation 也提供 XAML 支援型別, 而且在許多情況下, 這些都有與 WPF 對等的簡短名稱。Windows Workflow Foundation also provided XAML support types, and in many cases these had identical short names to a WPF equivalent. 以下是 Windows Workflow Foundation XAML 支援類型的清單:The following is a list of Windows Workflow Foundation XAML support types:

這些支援類型仍存在於 .NET Framework 4 的 Windows Workflow Foundation 元件中, 而且仍然可以用於特定的 Windows Workflow Foundation 應用程式;不過, 不應由不使用 Windows Workflow Foundation 的應用程式或架構參考。These support types still exist in the Windows Workflow Foundation assemblies for .NET Framework 4 and can still be used for specific Windows Workflow Foundation applications; however, they should not be referenced by applications or frameworks that do not use Windows Workflow Foundation.

MarkupExtensionMarkupExtension

在 .NET Framework 3.5 和 .NET Framework 3.0 中, WPF MarkupExtension的類別是在 WindowsBase 元件中。In the .NET Framework 3.5 and .NET Framework 3.0, the MarkupExtension class for WPF was in the WindowsBase assembly. System.workflow.componentmodel.activity 元件中已存在 Windows Workflow Foundation MarkupExtension的平行類別。A parallel class for Windows Workflow Foundation, MarkupExtension, existed in the System.Workflow.ComponentModel assembly. 在 .NET Framework 4 中, MarkupExtension類別會遷移至 system.object 元件。In the .NET Framework 4, the MarkupExtension class is migrated to the System.Xaml assembly. 在 .NET Framework 4 中, MarkupExtension適用于任何使用 .NET Framework xaml 服務的 xaml 擴充性情節, 而不只是針對特定架構所建立的物件。In the .NET Framework 4, MarkupExtension is intended for any XAML extensibility scenario that uses .NET Framework XAML Services, not just for those that build on specific frameworks. 進行 XAML 擴充時,也應盡可能將特定架構或架構中的使用者程式碼建置在 MarkupExtension 類別上。When possible, specific frameworks or user code in the framework should also build on the MarkupExtension class for XAML extension.

支援服務類別的 MarkupExtensionMarkupExtension Supporting Service Classes

WPF 的 .NET Framework 3.5 和 .NET Framework 3.0 提供了MarkupExtension數項服務, 可供實作者和TypeConverter實作為支援 XAML 中的類型/屬性使用。.NET Framework 3.5 and .NET Framework 3.0 for WPF provided several services that were available to MarkupExtension implementers and TypeConverter implementations to support type/property usage in XAML. 這些服務包括:These services are the following:

注意

與標記延伸相關的 .NET Framework 3.5 的另一個服務是IReceiveMarkupExtension介面。Another service from .NET Framework 3.5 that is related to markup extensions is the IReceiveMarkupExtension interface. IReceiveMarkupExtension尚未遷移, 並標示[Obsolete]為 .NET Framework 4。IReceiveMarkupExtension was not migrated and is marked [Obsolete] for .NET Framework 4. 先前使用 IReceiveMarkupExtension 的情節應改用 XamlSetMarkupExtensionAttribute 屬性化回呼。Scenarios that previously used IReceiveMarkupExtension should instead use XamlSetMarkupExtensionAttribute attributed callbacks. AcceptedMarkupExtensionExpressionTypeAttribute 也已標記為 [Obsolete]AcceptedMarkupExtensionExpressionTypeAttribute is also marked [Obsolete].

XAML 語言功能XAML Language Features

有數項 WPF 適用的 XAML 語言功能和元件先前存在於 PresentationFramework 組件中。Several XAML language features and components for WPF previously existed in the PresentationFramework assembly. 這些項目會以 MarkupExtension 子類別的形式實作,以在 XAML 標記中公開標記延伸使用。These were implemented as a MarkupExtension subclass to expose markup extension usages in XAML markup. 在 .NET Framework 4 中, 這些存在於 System.object 元件中, 因此不包含 WPF 元件的專案可以使用這些 XAML 語言層級功能。In .NET Framework 4, these exist in the System.Xaml assembly so that projects that do not include WPF assemblies can use these XAML language-level features. WPF 會針對 .NET Framework 4 應用程式使用這些相同的執行。WPF uses these same implementations for .NET Framework 4 applications. 如本主題所列的其他情況,支援類型會繼續存在於 System.Windows.Markup 命名空間中,以避免破壞先前的參考。As with the other cases that are listed in this topic, the supporting types continue to exist in the System.Windows.Markup namespace to avoid breaking previous references.

下表包含 System.Xaml 中定義的 XAML 功能支援類別清單。The following table contains a list of the XAML feature-support classes that are defined in System.Xaml.

XAML 語言功能XAML Language Feature 使用量Usage
ArrayExtension <x:Array ...>
NullExtension {x:Null}
StaticExtension {x:Static ...}
TypeExtension {x:Type ...}

雖然 System.Xaml 可能沒有特定支援類別,但處理 XAML 語言的語言功能時所需的一般邏輯,現已常駐於 System.Xaml 以及其實作的 XAML 讀取器和 XAML 寫入器中。Although System.Xaml may not have specific support classes, the general logic for processing language features for the XAML language now resides in System.Xaml and its implemented XAML readers and XAML writers. 例如, x:TypeArguments 是由 XAML 讀取器和 XAML 寫入器透過 System.Xaml 實作處理的屬性。該屬性可在 XAML 節點資料流中標註、在預設 (CLR 型) XAML 結構描述內容中有處理邏輯、具有 XAML 類型系統表示等。For example, x:TypeArguments is an attribute that is processed by XAML readers and XAML writers from System.Xaml implementations; it can be noted in the XAML node stream, has handling in the default (CLR-based) XAML schema context, has a XAML type-system representation, and so on. 因此,所有 XAML 語言層級功能的參考文件,都會是 XAML Services 和 .NET Framework 文件集該一般區域的子主題,而不會是 WPF 文件集中 進階 (Windows Presentation Foundation) 的子主題 (在 3.5 文件集中仍為如此)。As a result, the reference documentation for all XAML language-level features is a subtopic for XAML Services and that general area of the .NET Framework documentation set, instead of being part of the WPF documentation set as a subtopic of Advanced (Windows Presentation Foundation) (as is still the case in 3.5 documentation sets).

ValueSerializer 和支援類別ValueSerializer and Supporting Classes

ValueSerializer 類別支援將類型轉換成字串,尤其是在 XAML 序列化需要輸出中有多個模式或節點時。The ValueSerializer class supports type conversion to a string, particularly for XAML serialization cases where serialization may require multiple modes or nodes in the output. 在 .NET Framework 3.5 和 .NET Framework 3.0 中, ValueSerializer for WPF 的是在 WindowsBase 元件中。In .NET Framework 3.5 and .NET Framework 3.0, the ValueSerializer for WPF was in the WindowsBase assembly. 在 .NET Framework 4 中, ValueSerializer類別是在 system.string 中, 適用于任何 Xaml 擴充性情節, 而不只是在 WPF 上建立的實例。In the .NET Framework 4, the ValueSerializer class is in System.Xaml and is intended for any XAML extensibility scenario, not just for those that build on WPF. IValueSerializerContext (支援服務) 和 DateTimeValueSerializer (特定子類別) 也會移轉至 System.Xaml。IValueSerializerContext (a supporting service) and DateTimeValueSerializer (a specific subclass) are also migrated to System.Xaml.

WPF XAML 隨附數個可套用至 CLR 類型的屬性,以針對其 XAML 行為表示相關資訊。WPF XAML included several attributes that can be applied to CLR types to indicate something about their XAML behavior. 以下是在 .NET Framework 3.5 和 .NET Framework 3.0 中, 存在於 WPF 元件中的屬性清單。The following is a list of the attributes that existed in WPF assemblies in .NET Framework 3.5 and .NET Framework 3.0. 這些屬性會遷移至 .NET Framework 4 中的 System.object。These attributes are migrated to System.Xaml in .NET Framework 4.

其他類別Miscellaneous Classes

IComponentConnector介面存在於 .NET Framework 3.5 和 .NET Framework 3.0 中的 WindowsBase 中, 但存在於 .NET Framework 4 中的 system.object。The IComponentConnector interface existed in WindowsBase in the .NET Framework 3.5 and .NET Framework 3.0, but exists in System.Xaml in .NET Framework 4. IComponentConnector 主要用於工具支援和 XAML 標記編譯器。IComponentConnector is primarily intended for tooling support and XAML markup compilers.

INameScope介面存在於 .NET Framework 3.5 和 .NET Framework 3.0 中的 WindowsBase 中, 但存在於 .NET Framework 4 中的 system.object。The INameScope interface existed in WindowsBase in the .NET Framework 3.5 and .NET Framework 3.0, but exists in System.Xaml in .NET Framework 4. INameScope 為 XAML 名稱範圍定義基本作業。INameScope defines basic operations for a XAML namescope.

下列類別同時存在於 WPF 元件和 .NET Framework 4 中的 System.object 元件中:The following classes exist in both the WPF assemblies and the System.Xaml assembly in the .NET Framework 4:

XamlReader

XamlWriter

XamlParseException

WPF 實作位於 System.Windows.Markup 命名空間和 PresentationFramework 組件中。The WPF implementation is found in the System.Windows.Markup namespace, and PresentationFramework assembly. System.Xaml 實作位於 System.Xaml 命名空間中。The System.Xaml implementation is found in the System.Xaml namespace. 如果您使用 WPF 類型或衍生自 WPF 類型,通常應使用 XamlReaderXamlWriter 的 WPF 實作,而不是 System.Xaml 實作。If you are using WPF types or are deriving from WPF types, you should typically use the WPF implementations of XamlReader and XamlWriter instead of the System.Xaml implementations. 如需詳細資訊,請參閱 System.Windows.Markup.XamlReaderSystem.Windows.Markup.XamlWriter中的<備註>。For more information, see Remarks in System.Windows.Markup.XamlReader and System.Windows.Markup.XamlWriter.

如果您同時納入 WPF 組件和 System.Xaml 的參考,並且同時對 includeSystem.Windows.Markup 命名空間使用 System.Xaml 陳述式,則您可能必須完整限定對這些 API 的呼叫,以明確解析類型。If you are including references to both WPF assemblies and System.Xaml, and you also are using include statements for both the System.Windows.Markup and System.Xaml namespaces, you may need to fully qualify the calls to these APIs in order to resolve the types without ambiguity.

另請參閱See also