什么是通用 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.

安全Secure

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,它将在任何 Windows 10 设备上运行,不论你是定位台式电脑、Xbox、混合现实头戴显示设备还是其他设备。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. 所有 Windows 10 设备都实现这些 Win32 API。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

统一的 App Store 让你的应用在 Windows 10 设备(如电脑、平板电脑、Xbox、HoloLens、Surface Hub 和物联网 (IoT) 设备)上可用。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

向 Microsoft Store 提交应用Submit your app to the store

利用统一的新 Windows 开发人员中心仪表板,你可以在同一位置管理和提交所有面向 Windows 设备的应用。The new unified Windows Dev Center dashboard lets you manage and submit all of your apps for Windows devices in one place. 若要了解如何在 Microsoft Store 中提交应用以供发布,请参阅使用统一的 Windows 开发人员中心仪表板See Using the unified Windows Dev Center dashboard 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.

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

更多高级主题More advanced topics