从 WPF 迁移到 System.Xaml 的类型Types migrated from WPF to System.Xaml

在 .NET 框架 3.5 和 .NET 框架 3.0 中,Windows 演示基础 (WPF) 和 Windows 工作流基础都包含 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 工作流基础 XAML 提供扩展性的公共类型存在于 System.Workflow.组件模型程序集中。Likewise, public types that provided extensibility for Windows Workflow Foundation XAML existed in the System.Workflow.ComponentModel assembly. 在 .NET 框架 4 中,一些与 XAML 相关的类型已迁移到 System.Xaml 程序集。In the .NET Framework 4, some of the XAML-related types were migrated to the System.Xaml assembly. XAML 语言服务的通用 .NET 框架实现支持许多 XAML 扩展性方案,这些方案最初由特定框架的 XAML 实现定义,但现在是整体 .NET 框架 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 框架 3.5 和 .NET 框架 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 框架 4 中System.Xaml,有一个新的命名空间和一个新的 System.Xaml 程序集。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 工作流基础)的程序集。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. 因此,.NETSystem.Windows.Markup框架 4 中的命名空间包含一般 XAML 语言支持类型(来自 System.Xaml 程序集)和特定于 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). 在版本 4 的 WPF 程序集中,已迁移到 System.Xaml,但以前存在于 WPF 程序集中的任何类型都具有类型转发支持。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.

工作流 XAML 支持类型Workflow XAML Support Types

Windows 工作流基础还提供 XAML 支持类型,在许多情况下,这些类型与 WPF 等效项具有相同的短名称。Windows Workflow Foundation also provided XAML support types, and in many cases these had identical short names to a WPF equivalent. 以下是 Windows 工作流基础 XAML 支持类型的列表:The following is a list of Windows Workflow Foundation XAML support types:

这些支持类型仍然存在于 .NET 框架 4 的 Windows 工作流基础程序集中,但仍可用于特定的 Windows 工作流基础应用程序;但是,它们不应被不使用 Windows 工作流基础的应用程序或框架引用。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 框架 3.5 和 .NET 框架MarkupExtension3.0 中,WPF 的类位于 WindowsBase 程序集中。In the .NET Framework 3.5 and .NET Framework 3.0, the MarkupExtension class for WPF was in the WindowsBase assembly. Windows 工作流基础MarkupExtension的并行类存在于 System.Workflow.组件模型程序集中。A parallel class for Windows Workflow Foundation, MarkupExtension, existed in the System.Workflow.ComponentModel assembly. 在 .NET 框架 4MarkupExtension中,类将迁移到 System.Xaml 程序集。In the .NET Framework 4, the MarkupExtension class is migrated to the System.Xaml assembly. 在 .NET 框架MarkupExtension4 中,适用于使用 .NET 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.

MarkupExtension 支持服务类MarkupExtension Supporting Service Classes

WPF 的 .NET 框架 3.5 和 .NET 框架 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 框架 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 框架 4 中,这些功能存在于 System.Xaml 程序集中,以便不包含 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 框架 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 是一个由 System.Xaml 实现中的 XAML 读取器和 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 演示基础 (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 框架 3.5 和 .NETValueSerializer框架 3.0 中,WPF 的 是在 WindowsBase 程序集中。In .NET Framework 3.5 and .NET Framework 3.0, the ValueSerializer for WPF was in the WindowsBase assembly. 在 .NET 框架 4ValueSerializer中,该类位于 System.Xaml 中,适用于任何 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 框架 3.5 和 .NET 框架 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 框架 4 中的 System.Xaml。These attributes are migrated to System.Xaml in .NET Framework 4.

其他类Miscellaneous Classes

IComponentConnector接口存在于 .NET 框架 3.5 和 .NET 框架 3.0 中的 WindowsBase 中,但存在于 .NET 框架 4 中的 System.Xaml 中。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 框架 3.5 和 .NET 框架 3.0 中的 WindowsBase 中,但存在于 .NET 框架 4 中的 System.Xaml 中。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.

以下类存在于 .NET 框架 4 中的 WPF 程序集和 System.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.