WPF 与 Silverlight
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/944608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF vs Silverlight
提问by Sauron
Possible Duplicate:
What is the difference between WPF and Silverlight application?
What are the exact differences between WPF and Silverlight?
WPF 和 Silverlight 之间的确切区别是什么?
回答by SergioL
That's an extremely broad question. My company recently wrote a whitepaper outlining the differences between the two technologies, and it's around 70 pages. Unfortunately, it's not published yet, or I'd give you the link.
这是一个非常广泛的问题。我的公司最近写了一份白皮书,概述了这两种技术之间的差异,大约有 70 页。不幸的是,它还没有发布,或者我会给你链接。
EDIT: As promised, here's the link to the whitepaper on Codeplex:
http://wpfslguidance.codeplex.com/
编辑:正如所承诺的,这里是 Codeplex 白皮书的链接:http://wpfsluidance.codeplex.com/
However, I'll try to summarize.
不过,我会试着总结一下。
WPF is a thick Windows client platform that has access to the full .Net Framework. Silverlight is a browser-based technology that has access to a subset of the .Net Framework (called the CoreCLR). So, you'll notice differences using seemingly every day methods and objects within the framework. For instance, the Split() method on the String class has 3 overrides in Silverlight, but 6 in the .Net Framework. You'll see differences like this a lot.
Within WPF, all visually rendering elements derive from the Visual base class. Within Silverlight, they do not; instead, they derive from Control. Both technologies, however, eventual derive from the DependencyObject class up the hierarchy.
WPF, currently, ships or has available more user controls than Silverlight; though this difference is being mitigated through the Silverlight Toolkit and the upcoming release of Silverlight 3.
WPF supports 3 types of routed events (direct, bubbling, and tunneling). Silverlight supports direct and bubbling only.
There's quite a few data-binding differences that will be somewhat mitigated with the next version of Silverlight. Currently, Silverlight doesn't support the binding mode, OneWayToSource, or Explict UpdateSourceTriggers. In addition, Silverlight defaults to OneWay databinding if none is set, while WPF uses the default mode specified by the dependency property.
Silveright doesn't support MultiBinding.
Silverlight supports the XmlDataProvider but not the ObjectDataProvider. WPF supports both.
Silverlight can only make asynchronous network calls. WPF has access to the full .Net networking stack and can make any type of call. Also, currently, Silverlight supports SOAP, but can not handle SOAP fault exceptions natively (this may change in Silverlight 3).
There are huge differences in Cryptography (Silverlight has 20 classes in the namespace, while WPF has access to 107). Basically, Silverlight supports only 4 hashing algorithms and the AES encryption protocol.
Silverlight doesn't yet support: Commanding, Validation, Printing, XPS Documents, Speech, 3D, Freezable objects, or InterOp with the Windows Desktop; all of which are available in WPF.
Silverlight supports browser interop, more media streaming options including timeline markers, and Deep Zoom. WPF doesn't support these features yet.
WPF 是一个厚 Windows 客户端平台,可以访问完整的 .Net 框架。Silverlight 是一种基于浏览器的技术,可以访问 .Net Framework(称为 CoreCLR)的子集。因此,您会注意到在框架内使用看似日常的方法和对象的差异。例如,String 类上的 Split() 方法在 Silverlight 中有 3 个覆盖,但在 .Net Framework 中有 6 个。你会看到很多这样的差异。
在 WPF 中,所有视觉呈现元素都派生自 Visual 基类。在 Silverlight 中,它们没有;相反,它们源自 Control。但是,这两种技术最终都从层次结构中的 DependencyObject 类派生。
WPF 目前比 Silverlight 提供或拥有更多的用户控件;尽管这种差异正在通过 Silverlight Toolkit 和即将发布的 Silverlight 3 得到缓解。
WPF 支持 3 种类型的路由事件(直接、冒泡和隧道)。Silverlight 仅支持直接和冒泡。
下一个版本的 Silverlight 会稍微缓解一些数据绑定差异。目前,Silverlight 不支持绑定模式、OneWayToSource 或 Explict UpdateSourceTriggers。此外,如果没有设置,Silverlight 默认使用 OneWay 数据绑定,而 WPF 使用依赖属性指定的默认模式。
Silveright 不支持多重绑定。
Silverlight 支持 XmlDataProvider 但不支持 ObjectDataProvider。WPF 两者都支持。
Silverlight 只能进行异步网络调用。WPF 可以访问完整的 .Net 网络堆栈,并且可以进行任何类型的调用。此外,目前,Silverlight 支持 SOAP,但不能本机处理 SOAP 错误异常(这可能会在 Silverlight 3 中改变)。
密码学存在巨大差异(Silverlight 在命名空间中有 20 个类,而 WPF 可以访问 107 个)。基本上,Silverlight 仅支持 4 种散列算法和 AES 加密协议。
Silverlight 尚不支持:命令、验证、打印、XPS 文档、语音、3D、Freezable 对象或与 Windows 桌面的互操作;所有这些都在 WPF 中可用。
Silverlight 支持浏览器互操作、更多媒体流选项,包括时间线标记和深度缩放。WPF 尚不支持这些功能。
This is by no means complete as I was trying to reduce a 70-page document into bullet points.
这绝不是完整的,因为我试图将 70 页的文档缩减为要点。
Finally, even with all these differences, Microsoft is trying to close the gap between the two technologies. The Silverlight Toolkit and the WPF Toolkit both address some of the shortcomings of each technology. Silverlight 3 will be adding many features not currently available (such as element-to-element data binding). However, due to the differences in the core libraries, there will always be some Framework differences.
最后,即使存在所有这些差异,微软仍在努力缩小这两种技术之间的差距。Silverlight Toolkit 和 WPF Toolkit 都解决了每种技术的一些缺点。Silverlight 3 将添加许多当前不可用的功能(例如元素到元素的数据绑定)。但是,由于核心库的差异,总会有一些Framework的差异。
回答by samjudson
WPF is a Windows desktop technology for developing Windows application in the .Net framework.
WPF 是一种 Windows 桌面技术,用于在 .Net 框架中开发 Windows 应用程序。
Silverlight is a web technology, that is fully supported by a browser plugin on both Windows and MAC (in a similar fashion to Flash). There is also a plugin for running Silverlight on Linux (Moonlight).
Silverlight 是一种 Web 技术,Windows 和 MAC 上的浏览器插件完全支持它(与 Flash 类似)。还有一个用于在 Linux (Moonlight) 上运行 Silverlight 的插件。
While there are similarities between the functionality provided by both WPF and Silverlight (in terms of user interface components and support for XAML) Silverlight is a much small framework, containing a subset of WPF functionality. Newer versions of Silverlight actually contain some functionality not found in WPF, so it is no longer a true subset.
虽然 WPF 和 Silverlight 提供的功能之间存在相似之处(在用户界面组件和 XAML 支持方面),但 Silverlight 是一个非常小的框架,包含 WPF 功能的一个子集。较新版本的 Silverlight 实际上包含一些 WPF 中没有的功能,因此它不再是真正的子集。
回答by James Cadd
Things that WPF has that Silverlight doesn't: Full 3d engine based on DirectX, Windows integration such as Windows 7 taskbar thumbnails and system registry availability as well as access to the full .NET Framework including Oracle database support. Also, SL runs in a secure sandbox that prevents access to things such as the entire file system where WPF apps can run full trust with complete system access.
WPF 有 Silverlight 没有的东西:基于 DirectX 的完整 3d 引擎、Windows 集成(如 Windows 7 任务栏缩略图和系统注册表可用性)以及对完整 .NET Framework 的访问,包括 Oracle 数据库支持。此外,SL 在安全沙箱中运行,可防止访问诸如整个文件系统之类的内容,WPF 应用程序可以在其中运行完全信任并具有完整系统访问权限。
As mentioned above, SL pioneered some technologies such as the VisualStateManager which are making their was secondarily into WPF through the Microsoft supported WPF toolkit.
如上所述,SL 开创了 VisualStateManager 等一些技术,这些技术正在通过 Microsoft 支持的 WPF 工具包将其二次转化为 WPF。
If you're looking to gauge which technology is right for your project here's a simple way to look at it: If you're writing an app that's meant to run while disconnected from the web, or if you're writing an app that needs access to Windows specific features like the ones listed above then WPF is the way to go. For platform-agnostic, web enabled apps Silverlight is an appropriate choice. Hth.
如果您想确定哪种技术适合您的项目,这里有一个简单的方法来看待它:如果您正在编写一个旨在在与网络断开连接的情况下运行的应用程序,或者如果您正在编写一个需要访问上面列出的 Windows 特定功能,然后 WPF 是要走的路。对于与平台无关、支持 Web 的应用程序,Silverlight 是合适的选择。嗯。
回答by Andz
You could say that it is [VERY] roughly analogous to the difference between Flex and Adobe Air, but that is somewhat misleading.
您可以说它 [非常] 大致类似于 Flex 和 Adobe Air 之间的区别,但这有点误导。
WPF refers to the set of technologies (exposed via APIs) that .NET Framework 3.0 and above users have access to in order to draw to the screen.
WPF 是指 .NET Framework 3.0 及更高版本用户有权访问以绘制到屏幕的一组技术(通过 API 公开)。
Many of the WPF APIs are available for Silverlight apps.
许多 WPF API 可用于 Silverlight 应用程序。
There are, of course many other APIs besides WPF that are available under Silverlight since SL apps will need to do a lot more than just draw on the screen.
除了 WPF 之外,Silverlight 下当然还有许多其他 API 可用,因为 SL 应用程序需要做的不仅仅是在屏幕上绘制。