At the lowest level, WinRT is an object model defined on ABI level. It uses COM as a base (so every WinRT object implements IUnknown and does refcounting), and builds from there. 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. Of other notable things, WinRT also has parametrized ("generic") interfaces.
One other big change is that all WinRT components have metadata available for them, just like .NET assemblies. In COM you kinda sorta had that with typelibs, but not every COM component had them. For WinRT, the metadata is contained in .winmd files - look inside "C:\Program Files (x86)\Windows Kits\8.0\Windows Metadata\" in Developer Preview. If you poke around, you'll see that they are actually CLI assemblies with no code, just metadata tables. You can open them with ILDASM, in fact. Note, this doesn't mean that WinRT itself is managed - it simply reuses the file format.
然后,根据该对象模型实现了许多库——定义WinRT接口和类。再次,查看上面提到的“Windows元数据”文件夹,看看那里有什么;或者在VS中打开对象浏览器,在框架选择器中选择“Windows 8.0”,看看覆盖了什么。这里有很多内容,而且它不仅仅处理UI—您还可以获得Windows.Data这样的名称空间。Json,或者windows。graphics。打印,或者windows . networking . socket。
然后你会得到几个专门处理UI的库——这些库大多是Windows下的各种命名空间。UI或Windows.UI.Xaml。它们中的很多都非常类似于WPF/Silverlight的命名空间——例如Windows.UI.Xaml.Controls非常接近System.Windows.Controls;Windows.UI.Xaml.Documents等也是如此。
Now, .NET has the ability to directly reference WinRT components as if they were .NET assemblies. 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. 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. 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.
这也不是一个生硬的映射——CLR试图在可能的情况下使WinRT类型适应它们的等量物。例如,guid,日期和uri变成了系统。Guid,系统。日期时间和系统。Uri分别;WinRT收集接口如IIterable<T>和IVector<T>变成IEnumerable<T>和IList<T>;等等。这是双向的——如果你有一个。net对象实现了IEnumerable<T>,并将它传递回WinRT,它将看到它为IIterable<T>。
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. 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.
WinRT本身与HTML和CSS没有任何关系,它与JavaScript的关系只是在某种意义上,它也被暴露在那里,类似于它为。net所做的。当你在。net Metro应用程序中使用WinRT UI库时,你不需要处理HTML/CSS/JS(好吧,我猜,如果你真的想,你可以托管一个WebView控件…)你所有的。net和Silverlight技能在这个编程模型中仍然非常相关。