Windows 8 Runtime(WinRT / Windows应用商店应用程序/ Windows 10通用应用程序)与Silverlight和WPF相比如何? [关闭]

本文翻译自:How does Windows 8 Runtime (WinRT / Windows Store apps / Windows 10 Universal App) compare to Silverlight and WPF? [closed]

I am trying to get my head round the new Windows 8 Runtime that is used to create Metro style apps. 我试图了解用于创建Metro风格应用程序的新Windows 8 Runtime。 I know you can use it with XAML and it is based on .NET so C# and VB.NET can be used to write the apps, but then it seems to have something to do with HTML, CSS, DOM, and JavaScript. 我知道你可以在XAML上使用它,它基于.NET,所以C#和VB.NET可以用来编写应用程序,但它似乎与HTML,CSS,DOM和JavaScript有关。

Can someone explain what it is in a few paragraphs, in terms that a .NET UI programmer can understand? 根据.NET UI程序员可以理解的术语,有人可以用几段解释它是什么吗? (I am missing something “key” that is necessary to understand it.) (我错过了理解它所必需的“关键”。)


We all know that WPF, Silverlight , Windows Forms , etc. will keep working under Windows 8 (and Windows 10) on at least on Intel systems, so please don't tell me that... 我们都知道WPF, Silverlight , Windows Forms等将至少在英特尔系统上继续在Windows 8(和Windows 10)下运行,所以请不要告诉我......


#1楼

参考:https://stackoom.com/question/V7SE/Windows-Runtime-WinRT-Windows应用商店应用程序-Windows-通用应用程序-与Silverlight和WPF相比如何-关闭


#2楼

From the Build keynote: 从Build主题演讲:

They're providing common APIs to both HTML/CSS/JavaScript apps and C#/XAML apps. 他们为HTML / CSS / JavaScript应用程序和C#/ XAML应用程序提供通用API。 C# and XAML will be used, but it won't be WPF or Silverlight exactly. 将使用C#和XAML,但它不会完全是WPF或Silverlight。


#3楼

At the lowest level, WinRT is an object model defined on ABI level. 在最低级别,WinRT是在ABI级别上定义的对象模型。 It uses COM as a base (so every WinRT object implements IUnknown and does refcounting), and builds from there. 它使用COM作为基础(因此每个WinRT对象实现IUnknown并进行引用计数),并从那里构建。 It does add quite a lot of new concepts in comparison to COM of old, most of which come directly from .NET - for example, WinRT object model has delegates, and events are done .NET-style (with delegates and add/remove subscriber methods, one per event) rather than the old COM model of event sources and sinks. 与旧的COM相比,它确实添加了许多新概念,其中大多数直接来自.NET - 例如,WinRT对象模型具有委托,事件是.NET样式的(具有委托和添加/删除订阅者)方法,每个事件一个)而不是事件源和接收器的旧COM模型。 Of other notable things, WinRT also has parametrized ("generic") interfaces. 在其他值得注意的事情中,WinRT还具有参数化(“通用”)接口。

One other big change is that all WinRT components have metadata available for them, just like .NET assemblies. 另一个重大变化是所有WinRT组件都有可用的元数据,就像.NET程序集一样。 In COM you kinda sorta had that with typelibs, but not every COM component had them. 在COM中你有点类型与typelibs,但不是每个COM组件都有它们。 For WinRT, the metadata is contained in .winmd files - look inside "C:\\Program Files (x86)\\Windows Kits\\8.0\\Windows Metadata\\" in Developer Preview. 对于WinRT,元数据包含在.winmd文件中 - 在Developer Preview中查看“C:\\ Program Files(x86)\\ Windows Kits \\ 8.0 \\ Windows Metadata \\”。 If you poke around, you'll see that they are actually CLI assemblies with no code, just metadata tables. 如果你四处寻找,你会发现它们实际上是没有代码的CLI程序集,只有元数据表。 You can open them with ILDASM, in fact. 实际上,您可以使用ILDASM打开它们。 Note, this doesn't mean that WinRT itself is managed - it simply reuses the file format. 注意,这并不意味着WinRT本身是受管理的 - 它只是重用文件格式。

Then there are a number of libraries implemented in terms of that object model - defining WinRT interfaces and classes. 然后根据该对象模型实现了许多库 - 定义WinRT接口和类。 Again, look at "Windows Metadata" folder mentioned above to see what's there; 再次,看看上面提到的“Windows Metadata”文件夹,看看那里有什么; or just fire up Object Browser in VS and select "Windows 8.0" in the framework selector, to see what's covered. 或者只是在VS中启动对象浏览器并在框架选择器中选择“Windows 8.0”,以查看所涵盖的内容。 There's a lot there, and it doesn't deal with UI alone - you also get namespaces such as Windows.Data.Json , or Windows.Graphics.Printing , or Windows.Networking.Sockets . 那里有很多,并且它不仅仅涉及UI - 您还可以获得名称空间,例如Windows.Data.JsonWindows.Graphics.PrintingWindows.Networking.Sockets

Then you get several libraries, which are specifically dealing with UI - mostly these would be various namespaces under Windows.UI or Windows.UI.Xaml . 然后你会得到几个专门处理UI的库 - 主要是Windows.UIWindows.UI.Xaml下的各种命名空间。 A lot of them are very similar to WPF/Silverlight namespaces - eg Windows.UI.Xaml.Controls is closely matching System.Windows.Controls ; 其中很多都与WPF / Silverlight命名空间非常相似 - 例如Windows.UI.Xaml.ControlsSystem.Windows.Controls紧密匹配; ditto for Windows.UI.Xaml.Documents etc. 同上,适用于Windows.UI.Xaml.Documents等。

Now, .NET has the ability to directly reference WinRT components as if they were .NET assemblies. 现在,.NET能够直接引用WinRT组件,就好像它们是.NET程序集一样。 This works differently from COM Interop - you don't need any intermediate artifacts such as interop assemblies, you just /r a .winmd file, and all types and their members in its metadata become visible to you as if they were .NET objects. 这与COM Interop的工作方式不同 - 您不需要任何中间工件(例如互操作程序集),只需要/r a .winmd文件,并且其元数据中的所有类型及其成员对您来说都是可见的,就像它们是.NET对象一样。 Note that WinRT libraries themselves are fully native (and so native C++ programs that use WinRT do not require CLR at all) - the magic to expose all that stuff as managed is inside the CLR itself, and is fairly low level. 请注意,WinRT库本身是完全本机的(因此使用WinRT的本机C ++程序根本不需要CLR) - 将所有这些东西公开为托管的魔力都在CLR本身内,并且是相当低级别的。 If you ildasm a .NET program that references a .winmd, you'll see that it actually looks like an extern assembly reference - there's no sleight of hand trickery such as type embedding there. 如果你ildasm一个引用.winmd的.NET程序,你会发现它实际上看起来像是一个extern汇编引用 - 没有任何手工技巧,比如在那里嵌入类型。

It's not a blunt mapping, either - CLR tries to adapt WinRT types to their equivalents, where possible. 它也不是一种生硬的映射 - 在可能的情况下,CLR会尝试将WinRT类型调整为等效类型。 So eg GUIDs, dates and URIs become System.Guid , System.DateTime and System.Uri , respectively; 因此,例如GUID,日期和URI分别成为System.GuidSystem.DateTimeSystem.Uri ; WinRT collection interfaces such as IIterable and IVector become IEnumerable and IList ; 诸如IIterableIVector类的WinRT集合接口变为IEnumerableIList ; and so on. 等等。 This goes both ways - if you have a .NET object that implements IEnumerable , and pass it back to WinRT, it'll see it as IIterable . 这有两种方式 - 如果你有一个实现IEnumerable的.NET对象,并将其传递回WinRT,它会将其视为IIterable

Ultimately, what this means is that your .NET Metro apps get access to a subset of the existing standard .NET libraries, and also to (native) WinRT libraries, some of which - particularly Windows.UI - look very similar to Silverlight, API-wise. 最终,这意味着您的.NET Metro应用程序可以访问现有标准.NET库的一部分,也可以访问(本机)WinRT库,其中一些(特别是Windows.UI与Silverlight,API非常相似-明智的。 You still have XAML to define your UI, and you still deal with the same basic concepts as in Silverlight - data bindings, resources, styles, templates etc. In many cases, it is possible to port a Silverlight app simply by using the new namespaces, and tweaking a few places in code where the API was adjusted. 你仍然有XAML来定义你的UI,你仍然处理与Silverlight相同的基本概念 - 数据绑定,资源,样式,模板等。在许多情况下,只需using新的命名空间就可以移植Silverlight应用程序。 ,并在调整API的代码中调整一些位置。

WinRT itself doesn't have anything to do with HTML and CSS, and it bears relation to JavaScript only in a sense that it is also exposed there, similar to how it is done for .NET. WinRT本身与HTML和CSS没有任何关系,它与JavaScript有关,只是在某种意义上它也暴露在那里,类似于.NET的工作方式。 You don't need to deal with HTML/CSS/JS when you use WinRT UI libraries in your .NET Metro app (well, I guess, if you really want to, you can host a WebView control...). 当你在.NET Metro应用程序中使用WinRT UI库时,你不需要处理HTML / CSS / JS(我想,如果你真的想,你可以托管一个WebView控件......)。 All your .NET and Silverlight skills remain very much relevant in this programming model. 您的所有.NET和Silverlight技能在此编程模型中仍然非常相关。


#4楼

Lots of detail from Microsoft here . 这里有很多来自微软的细节。

The Windows Runtime is exposed using API metadata (.winmd files). 使用API​​元数据(.winmd文件)公开Windows运行时。 This is the same format used by the .NET framework (Ecma-335). 这与.NET框架(Ecma-335)使用的格式相同。 The underlying binary contract makes it easy for you to access the Windows Runtime APIs directly in the development language of your choice. 底层二进制合约使您可以轻松地使用您选择的开发语言直接访问Windows运行时API。 The shape and structure of the Windows Runtime APIs can be understood by both static languages such as C# and dynamic languages such as JavaScript. Windows运行时API的形状和结构可以通过静态语言(如C#)和动态语言(如JavaScript)来理解。 IntelliSense is available in JavaScript, C#, Visual Basic, and C++. IntelliSense提供JavaScript,C#,Visual Basic和C ++。

In short, Windows Runtime is a new set of libraries exposing Windows functionality and available to JavaScript/C#/VB/C++. 简而言之,Windows Runtime是一组新的库,提供Windows功能,可用于JavaScript / C#/ VB / C ++。 Each language has been made to understand and be able to call them directly rather than having to go through some thunking layer. 每种语言都是为了理解并能够直接调用它们而不是通过一些thunking层。

Silverlight and WPF are flavors of XAML that run on the CLR. Silverlight和WPF是在CLR上运行的XAML的风格。 Among other functionality, Windows Runtime exposes a version of XAML very similar to Silverlight, but does so in a native way, not via the CLR. 在其他功能中,Windows运行时公开的XAML版本与Silverlight非常相似,但是以本机方式,而不是通过CLR。 It can be accessed from the CLR, but also from C++. 它可以从CLR访问,也可以从C ++访问。


#5楼

The key idea is that now there is two development tracks - the Desktop and Metro. 关键的想法是,现在有两个开发轨道 - 桌面和地铁。

  • The desktop is where the old apps live. 桌面是旧应用程序所在的位置。
  • The new class of applications, Metro applications, can be built in a number of ways, including by VB.NET, C# or C++. 新的应用程序类Metro应用程序可以通过多种方式构建,包括VB.NET,C#或C ++。 These three language options can use XAML for building the UI. 这三种语言选项可以使用XAML来构建UI。 The alternative is to use JavaScript/HTML5/CSS for the development of both the UI and application code. 另一种方法是使用JavaScript / HTML5 / CSS来开发UI和应用程序代码。

Some important points: 一些要点:

  • Windows 8 feels sort of like an upscaled mobile phone OS. Windows 8感觉有点像升级的手机操作系统。
  • In Metro, there are no overlapping top-level windows, just as there are none on a mobile phone. 在Metro中,没有重叠的顶层窗口,就像手机上没有窗口一样。 If you want an MDI style application, you need to stay on the desktop. 如果您需要MDI样式的应用程序,则需要保留在桌面上。
  • Metro style apps are automatically suspended when not visible. Metro风格的应用程序在不可见时会自动暂停。 This was done to prolong battery life. 这样做是为了延长电池寿命。 This means it won't make sense for many existing desktop apps, which perform background processing even while the user is not interacting with them, to be ported to Metro. 这意味着对于许多现有的桌面应用程序来说,即使在用户没有与它们交互时执行后台处理,移植到Metro也没有意义。
  • The ARM version of Windows 8 will not support desktop applications. ARM版本的Windows 8不支持桌面应用程序。 So if you want to write an app and you want it to work on any version of Windows then it has to be a Metro app. 因此,如果您想编写一个应用程序,并希望它可以在任何版本的Windows上运行,那么它必须是一个Metro应用程序。

#6楼

There's modified version of the architecture that'll surely help you understand where exactly the things lies. 这个架构的修改版本肯定会帮助您了解事情的确切位置。 One of the Telerik ninjas had chat with the CLR team and modified the picture: 其中一名Telerik忍者与CLR团队聊天并修改了图片:

Here you can see where the CLR stands. 在这里你可以看到CLR的位置。 The .NET framework now has two profiles .NET框架现在有两个配置文件

1- .NET Metro profile (CLR that deal with Metro application) 1- .NET Metro配置文件(处理Metro应用程序的CLR)

2- .NET Client profile (CLR runtime for C# and VB.NET applications) 2- .NET客户端配置文件(C#和VB.NET应用程序的CLR运行时)

I hope this gives you a clearer picture. 我希望这能给你一个更清晰的画面。 Read the full article in A bad picture is worth a thousand long discussions. 阅读完整的文章一张糟糕的图片值得长时间讨论。 .

你可能感兴趣的:(wpf,windows-runtime,windows-10)