什么是通用 Windows 平台 (UWP) 应用?What's a Universal Windows Platform (UWP) app?

通用 Windows 平台应用的各种设备上运行,支持自适应用户界面、 自然用户输入、 一个存储、 合作伙伴中心和云服务

UWP 应用是:A UWP app is:

  • 安全:UWP 应用程序声明哪些设备资源和他们访问的数据。Secure: UWP apps declare which device resources and data they access. 用户必须对该访问授权。The user must authorize that access.
  • 能够在运行 Windows 10 的所有设备上使用常见的 API。Able to use a common API on all devices that run Windows 10.
  • 可以使用设备的特定功能并让 UI 适应不同的设备屏幕尺寸、分辨率和 DPI。Able to use device specific capabilities and adapt the UI to different device screen sizes, resolutions, and DPI.
  • 通过运行 Windows 10 的所有设备(或只是你指定的设备)上的 Microsoft Store 提供。Available from the Microsoft Store on all devices (or only those that you specify) that run on Windows 10. Microsoft Store 提供了多种利你的应用赚钱的方式。The Microsoft Store provides multiple ways to make money on your app.
  • 能够在不对计算机构成风险或引起“计算机腐烂”的情况下安装和卸载。Able to be installed and uninstalled without risk to the machine or incurring "machine rot".
  • 吸引:使用动态磁贴、推送通知以及与 Windows 时间线和 Cortana 的“Pick Up Where I Left Off”交互的用户活动吸引用户。Engaging: use live tiles, push notifications, and user activities that interact with Windows Timeline and Cortana's Pick Up Where I Left Off, to engage users.
  • 可使用 C#、C++、Visual Basic 和 Javascript 编程。Programmable in C#, C++, Visual Basic, and Javascript. 对于 UI,使用 XAML、HTML 或 DirectX。For UI, use XAML, HTML, or DirectX.

让我们来看一下更详细的介绍。Let's look at these in more detail.


UWP 应用在其清单中声明所需的设备能力,如访问麦克风、位置、网络摄像头、USB 设备、文件等。UWP apps declare in their manifest the device capabilities they need such as access to the microphone, location, Webcam, USB devices, files, and so on. 用户必须在应用被授予能力前确认并授权该访问。The user must acknowledge and authorize that access before the app is granted the capability.

跨所有设备的通用 API 设计面A common API surface across all devices

Windows 10 引入了通用 Windows 平台 (UWP),它提供一个通用应用平台上运行 Windows 10 的每个设备。Windows 10 introduces the Universal Windows Platform (UWP), which provides a common app platform on every device that runs Windows 10. UWP 核心 API 在所有 Windows 设备上是相同的。The UWP core APIs are the same on all Windows devices. 如果您的应用程序仅使用核心 Api,它将面向的台式计算机、 Xbox、 混合现实耳机,无论任何 Windows 10 设备上运行,依此类推。If your app only uses the core APIs, it will run on any Windows 10 device no matter whether you are targeting a desktop PC, Xbox, Mixed-reality headset, and so on.

使用 C++ /WinRT 或 C++ /CX 编写的 UWP 应用可以访问属于 UWP 的 Win32 API。A UWP app written in C++ /WinRT or C++ /CX has access to the Win32 APIs that are part of the UWP. 这些 Win32 Api 被实现的所有 Windows 10 设备。These Win32 APIs are implemented by all Windows 10 devices.

扩展 SDK 公开特定设备类型的特殊能力Extension SDKs expose the unique capabilities of specific device types

如果你要使用通用 API,你的应用可以在运行 Windows 10 的所有设备上运行。If you target the universal APIs, your app can run on all devices that run Windows 10. 但是如果你希望 UWP 应用利用设备特定的 API,则可以。But if you want your UWP app to take advantage of device specific APIs, you can.

扩展 SDK 让你可以为不同设备调用专用的 API。Extension SDKs let you call specialized APIs for different devices. 例如,如果你的 UWP 应用面向 IoT 设备,则可以在项目中添加 IoT 扩展 SDK 以利用特定于 IoT 设备的功能。For example, if your UWP app targets an IoT device, you can add the IoT extension SDK to your project to target features specific to IoT devices. 有关添加扩展 SDK 的详细信息,请参阅设备系列概述扩展 SDK 部分。For more information about adding extension SDKs, see the Extension SDKs section in Device families overview.

你可以编写应用,以让它仅在特定类型的设备上运行,然后限制从 Microsoft Store 将它分发到该设备类型。You can write your app so that you expect it to run only on a particular type of device, and then limit its distribution from the Microsoft Store to just that type of device. 或者,你可以有条件地测试 API 在运行时的状态,并相应调整应用的行为。Or, you can conditionally test for the presence of an API at runtime and adapt your app's behavior accordingly. 有关详细信息,请参阅设备系列概述编写代码部分。For more information, see the Writing Code section in Device families overview.

以下视频提供对设备系列和自适应编码的简要概述:The following video provides a brief overview of device families and adaptive coding:

自适应控制和输入Adaptive controls and input

UI 元素通过调整其布局和比例响应应用所运行屏幕的尺寸和 DPI。UI elements respond to the size and DPI of the screen the app is running on by adjusting their layout and scale. UWP 应用与多种输入类型(如键盘、鼠标、触摸、笔和 Xbox One 控制器)配合良好。UWP apps work well with multiple types of input such as keyboard, mouse, touch, pen, and Xbox One controllers. 如果你需要进一步为特定屏幕大小或设备定制 UI,新的布局面板和工具将帮助你设计可以适应运行应用的不同设备和外形规格的 UI。If you need to further tailor your UI to a specific screen size or device, new layout panels and tooling help you design UI that can adapt to the different devices and form factors that your app may run on.

Windows 支持的设备

Windows 通过以下功能帮助你的 UI 面向多个设备:Windows helps you target your UI to multiple devices with the following features:

  • 通用控件和布局面板可帮助你针对设备的屏幕分辨率优化你的 UI。Universal controls and layout panels help you to optimize your UI for the screen resolution of the device. 例如,按钮和滑块等控件将自动适应设备屏幕的尺寸和 DPI 密度。For example, controls such as buttons and sliders automatically adapt to device screen size and DPI density. 布局面板根据屏幕尺寸帮助调整内容的布局。Layout panels help adjust the layout of content based on the size of the screen. 自适应缩放用于调整以适应不同设备的分辨率和 DPI。Adaptive scaling adjusts to resolution and DPI differences across devices.
  • 常用的输入处理允许你通过触摸、笔、鼠标、键盘或控制器(如 Microsoft Xbox 控制器)接收输入。Common input handling allows you to receive input through touch, a pen, a mouse, a keyboard, or a controller such as a Microsoft Xbox controller.
  • 工具可以帮助你设计出能够适应不同屏幕分辨率的 UI。Tooling that helps you to design UI that can adapt to different screen resolutions.

你的应用 UI 的某些方面将自动适应不同的设备。Some aspects of your app's UI will automatically adapt across devices. 但是,你的应用的用户体验设计可能需要根据正在运行该应用的设备进行调整。Your app's user-experience design, however, may need to adapt depending on the device the app is running on. 例如,照片应用在手持式小型设备上运行时可以调整其 UI,以确保该用法是单手使用的理想之选。For example, a photo app could adapt its UI when running on a small, handheld device to ensure that usage is ideal for single-handed use. 当照片应用在台式机上运行时,UI 应进行调整以充分利用额外的屏幕空间。When a photo app is running on a desktop computer, the UI should adapt to take advantage of the additional screen space.

存在一个适用于所有设备的应用商店There's one store for all devices

统一的应用商店使您的应用程序等 PC、 平板电脑、 Xbox、 HoloLens、 Surface Hub 和物联网 (IoT) 设备的 Windows 10 设备上可用。A unified app store makes your app available on Windows 10 devices such as PC, tablet, Xbox, HoloLens, Surface Hub, and Internet of Things (IoT) devices. 你可以向 Microsoft Store 提交应用,并使其对所有类型的设备或仅对所选设备类型可用。You can submit your app to the store and make it available to all types of devices, or only those you choose. 你将在一个位置上提交和管理适用于 Windows 设备的所有应用。You submit and manage all your apps for Windows devices in one place. 想要使用 UWP 功能实现 C++ 桌面应用的现代化并将其在 Microsoft store 内出售?Have a C++ desktop app that you want to modernize with UWP features and sell in the Microsoft store? 这同样可以实现。That's okay, too.

UWP 应用与 Application Insights 集成以获得详细的遥测和分析 - 用于了解用户、改进应用的重要工具。UWP apps integrate with Application Insights for detailed telemetry and analytics—a crucial tool for understanding your users and improving your apps.

获取应用收益Monetize your app

你可以选择如何获取应用收益。You can choose how you'll monetize your app. 可以通过多种方法利用你的应用盈利。There are a number of ways to make money with your app. 你只需选择最适合自身的方式即可,例如:All you need to do is choose the one that works best for you, for example:

  • 付费下载是最简单的选项,A paid download is the simplest option. 你只需指定价格即可。Just name the price.
  • 试用允许用户在购买前先试用你的应用,与更传统的“免费模式”选项相比,用户更易于发现你的应用并转而使用该应用。Trials let users try your app before buying it, providing easier discoverability and conversion than the more traditional "freemium" options.
  • 激励用户的促销价格。Sale prices to incentivize users.
  • 此外还提供应用内购买和广告。In-app purchases and ads are also available.

来自 Microsoft Store 的应用提供无缝的安装、卸载和升级体验Apps from the Microsoft Store provide a seamless install, uninstall, and upgrade experience

所有 UWP 应用均使用保护用户、设备和系统的打包系统分发。All UWP apps are distributed using a packaging system that protects the user, device, and system. 用户绝对不会后悔安装应用,因为 UWP 应用在卸载后除了应用所创建的文档外不会有任何残留。Users never need regret installing an app because UWP apps can be uninstalled without leaving anything behind except the documents created with the app.

应用可以无缝部署和更新。Apps can be deployed and updated seamlessly. 应用打包可以实现模块化,以便你可以根据需要下载内容和扩展。App packaging can be modularized so that you can download content and extensions on demand.

向用户提供相关且实时的信息以吸引他们再次访问Deliver relevant, real-time info to your users to keep them coming back

保持用户积极使用你的 UWP 应用有多种方法:There are a variety of ways to keep users engaged with your UWP app:

  • 动态磁贴和锁屏界面磁贴可以从应用中显示上下文相关且实时的信息概览。Live tiles and lock screen tiles that show contextually relevant and timely info from your app at a glance.
  • 推送通知可提供实时提醒来引起用户的注意。Push notifications that bring real-time alerts to your user’s attention.
  • 用户活动允许用户在应用中上次中断的位置继续,甚至可以跨设备实现。User Activities allow users to pick up where they left off in your app, even across devices.
  • “操作中心”管理来自应用的通知。The Action Center organizes notifications from your app.
  • 后台执行和触发器使你的应用仅在用户需要时才会运行。Background execution and triggers bring your app into action when the user needs it.
  • 你的应用可以使用语音和蓝牙 LE 设备 来帮助用户与周围的世界进行交互。Your app can use voice and Bluetooth LE devices to help users interact with the world around them.
  • 集成 Cortana 以将语音命令功能添加到你的应用。Integrate Cortana to add voice command capability to your app.

使用一种你已知道的语言Use a language you already know

UWP 应用可以使用 Windows 运行时,它是操作系统提供的本机 API。UWP apps use the Windows Runtime, the native API provided by the operating system. 此 API 通过 C++ 实现,并且在 C#、Visual Basic、C++ 和 JavaScript 中均受支持。This API is implemented in C++ and is supported in C#, Visual Basic, C++, and JavaScript. 适用于编写 UWP 应用的部分选项包括:Some options for writing UWP apps include:

  • XAML UI 和 C#、VB 或 C++XAML UI and C#, VB, or C++
  • DirectX UI 和 C++DirectX UI and C++
  • JavaScript 和 HTMLJavaScript and HTML

准备工作Get set up

查看准备工作以下载创建应用所需的工具,然后再编写你的第一个应用Check out Get set up to download the tools you need to start creating apps, and then write your first app.

设计你的应用Design your app

Microsoft 的设计系统名为 Fluent。The Microsoft design system is named Fluent. Fluent Design 系统是一套结合了最佳实践的 UWP 功能,用于创建在所有类型的支持 Windows 的设备上都表现出色的应用。The Fluent Design System is a set of UWP features combined with best practices for creating apps that perform beautifully on all types of Windows-powered devices. Fluent 体验能够适应各类设备,并提供自然的使用感受,从平板电脑到笔记本电脑,从电脑到电视,再到虚拟现实设备。Fluent experiences adapt and feel natural on devices from tablets to laptops, from PCs to televisions, and on virtual reality devices. 有关 Fluent Design 的简介,请参阅 UWP 应用的 Fluent Design 系统See The Fluent Design System for UWP apps for an introduction to Fluent Design.

除了确定应用外观和运行方式外,良好的设计还是确定用户如何与你的应用交互的过程。Good design is the process of deciding how users will interact with your app, in addition to how it will look and function. 用户体验极大地影响着用户对你的应用的满意度,所以请勿忽略此步骤。User experience plays a huge part in determining how happy people will be with your app, so don't skimp on this step. 设计基础知识介绍了如何设计通用 Windows 应用。Design basics introduces you to designing a Universal Windows app. 有关设计出令用户满意的 UWP 应用的信息,请参阅面向设计人员的通用 Windows 平台 (UWP) 应用简介See the Introduction to Universal Windows Platform (UWP) apps for designers for information on designing UWP apps that delight your users. 在开始编写代码之前,请参阅设备入门,以帮助你全面考虑在你要针对的所有不同外形规格上使用应用的交互体验。Before you start coding, see the device primer to help you think through the interaction experience of using your app on all the different form factors you want to target.

除了在不同设备上的交互外,还需规划应用以利用在多个设备之间运行的优势。In addition to interaction on different devices, plan your app to embrace the benefits of working across multiple devices. 例如:For example:

添加服务Add services

向应用商店提交应用Submit your app to the Store

合作伙伴中心允许你管理并提交所有应用程序以通过在一个位置的 Windows 设备。Partner Center lets you manage and submit all of your apps for Windows devices in one place. 请参阅发布 Windows 应用和游戏若要了解如何提交应用程序以通过 Microsoft Store 中发布。See Publish Windows apps and games to learn how to submit your apps for publication in the Microsoft Store.

新功能简化了流程,同时给予您更多的控制。New features simplify processes while giving you more control. 你还会找到与付款详细信息组合的详细分析报告推广你的应用并与客户互动的方式,等等。You'll also find detailed analytic reports combined payout details, ways to promote your app and engage with your customers, and much more.

有关更多入门材料,请参阅生成适用于 Windows 10 设备的 Windows 应用简介For more introductory material, see An Introduction to Building Windows Apps for Windows 10 Devices

更多高级主题More advanced topics

通用 Windows 平台如何与 Windows 运行时 Api 相关联How the Universal Windows Platform relates to Windows Runtime APIs

如果您正在构建的通用 Windows 平台 (UWP) 应用,你可以获取大量里程和方便性带术语"通用 Windows 平台 (UWP)"和"Windows 运行时 (WinRT)"视为同义词,增加或减少。If you're building a Universal Windows Platform (UWP) app, then you can get a lot of mileage and convenience out of treating the terms "Universal Windows Platform (UWP)" and "Windows Runtime (WinRT)" as more or less synonymous. 但它可能要查看的技术,在后台,并确定只是什么之处在于这些观点之间。But it is possible to look under the covers of the technology, and determine just what the difference is between those ideas. 如果您希望了解它,最后一部分是为您。If you're curious about that, then this last section is for you.

Windows 运行时和 WinRT Api 是一种演变,Windows Api。The Windows Runtime, and WinRT APIs, are an evolution of Windows APIs. 最初,Windows 通过平直的、 C 样式 Win32 Api 编写。Originally, Windows was programmed via flat, C-style Win32 APIs. 已添加到那些 COM Api (DirectX是一个重要例子)。To those were added COM APIs (DirectX being a prominent example). Windows 窗体、 WPF、.NET 和托管的语言引入其自己的方式编写 Windows 应用和 API 技术自己风格。Windows Forms, WPF, .NET, and managed languages brought their own way of writing Windows apps, and their own flavor of API technology. Windows 运行时,事实上下, 一阶段的 com。The Windows Runtime is, under the covers, the next stage of COM. 在实际的应用程序二进制接口 (ABI) 层,其根在 COM 中的变得可见。At the actual application binary interface (ABI) layer, its roots in COM become visible. 但 Windows 运行时的设计目标是通过一系列强大的不同的编程语言可调用。But the Windows Runtime was designed to be callable from a great range of different programming languages. 并可调用到每个这些语言很自然的方式。And callable in a way that's very natural to each of those languages. 为此,对 Windows 运行时访问,可通过所谓的语言投射。To this end, access to the Windows Runtime is made available via what are known as language projections. 没有 Windows 运行时语言投影到C#,为 Visual Basic 中,为标准C++、 到 JavaScript 中,依次类推。There is a Windows Runtime language projection into C#, into Visual Basic, into standard C++, into JavaScript, and so on. 此外,一次打包适当地 (请参阅桌面桥),可从一个很好范围的应用程序模型中生成应用程序中调用 WinRT Api:Win32、.NET、 WinForms 和 WPF。Furthermore, once packaged appropriately (see Desktop Bridge), you can call WinRT APIs from an app built in one of a great range of application models: Win32, .NET, WinForms, and WPF.

并且,当然,从 UWP 应用调用 WinRT Api。And, of course, you can call WinRT APIs from your UWP app. UWP 是构建在 Windows 运行时之上的应用程序模型。UWP is an application model built on top of the Windows Runtime. 从技术上讲,基于 UWP 应用程序模型CoreApplication,尽管此详细信息可能会隐藏的具体取决于所选的编程语言。Technically, the UWP application model is based on CoreApplication, although that detail may be hidden from you, depending on your choice of programming language. 如本主题已所述,从价值主张的角度来看,UWP 有助于编写单一的二进制文件,可以选择,将发布到 Microsoft Store 且很好的设备外观造型范围的任意一个上运行。As this topic has explained, from a value proposition point of view, the UWP lends itself to writing a single binary that can, should you choose, be published to the Microsoft Store and run on any one of a great range of device form factors. 对 UWP 应用的设备覆盖范围取决于 UWP Api 的子集,限制应用于调用,或有条件地调用。The device reach of your UWP app depends on the subset of UWP APIs that you limit your app to calling, or that you call conditionally.

希望本部分已成功在描述基础 Windows 运行时 Api 的机制和通用 Windows 平台的商业价值的技术之间的差异。Hopefully, this section has been successful in describing the difference between the technology underlying Windows Runtime APIs, and the mechanism and business value of the Universal Windows Platform.