從 WPF 遷移至 System.object 的類型Types migrated from WPF to System.Xaml

在 .NET Framework 3.5 和 .NET Framework 3.0 中,Windows Presentation Foundation (WPF) 和 Windows Workflow Foundation 都包含 XAML 語言的執行。In .NET Framework 3.5 and .NET Framework 3.0, both 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 提供擴充性的公用類型存在於 ComponentModel 元件中。Likewise, public types that provided extensibility for Windows Workflow Foundation XAML existed in the System.Workflow.ComponentModel assembly. 在 .NET Framework 4 中,某些與 XAML 相關的類型已遷移至 System.object 元件。In the .NET Framework 4, some of the XAML-related types were 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 article lists the types that were 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. 因此, System.Windows.Markup .NET Framework 4 中的命名空間包含混合的一般 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 中, MarkupExtension WPF 的類別位於 WindowsBase 元件中。In the .NET Framework 3.5 and .NET Framework 3.0, the MarkupExtension class for WPF was in the WindowsBase assembly. Windows Workflow Foundation 的 parallel 類別存在於 MarkupExtension ComponentModel 元件中。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 Xaml 服務的 XAML 擴充性情節,而不只是針對在特定架構上建立的 xaml 擴充性案例。In the .NET Framework 4, MarkupExtension is intended for any XAML extensibility scenario that uses .NET 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 語言層級功能的參考檔,都是《 Windows Presentation Foundation (WPF) 的桌面指南xaml 服務的子主題。As a result, the reference documentation for all XAML language-level features is a subtopic for XAML Services in the Desktop Guide for Windows Presentation Foundation (WPF).

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 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 中,這些屬性會遷移至 .Xaml。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 .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 .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 的 .Xaml 元件中:The following classes exist in both the WPF assemblies and the System.Xaml assembly in .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.