时间选取器Time picker

时间选取器提供了一种标准化途径,可使用户使用触摸、鼠标或键盘输入选取时间值。The time picker gives you a standardized way to let users pick a time value using touch, mouse, or keyboard input.

时间选取器示例

获取 Windows UI 库Get the Windows UI Library

WinUI 徽标

Windows UI 库 2.2 或更高版本包含此控件的使用圆角的新模板。Windows UI Library 2.2 or later includes a new template for this control that uses rounded corners. 有关详细信息,请参阅圆角半径For more info, see Corner radius. WinUI 是一种 NuGet 包,其中包含用于 Windows 应用的新控件和 UI 功能。WinUI is a NuGet package that contains new controls and UI features for Windows apps. 有关详细信息(包括安装说明),请参阅 Windows UI 库For more info, including installation instructions, see Windows UI Library.

平台 APITimePicker 类Time 属性Platform APIs: TimePicker class, Time property

这是正确的控件吗?Is this the right control?

使用时间选取器使用户可以选取单个时间值。Use a time picker to let a user pick a single time value.

有关选择正确控件的详细信息,请参阅日期和时间控件文章。For more info about choosing the right control, see the Date and time controls article.

示例Examples

XAML 控件库XAML Controls Gallery
XAML controls gallery

如果已安装 XAML 控件库应用,请单击此处打开此应用,了解 TimePicker 的实际应用If you have the XAML Controls Gallery app installed, click here to open the app and see the TimePicker in action.

入口点显示选定的时间,当用户选择该入口点时,会从中间垂直展开一个选取器图面以供用户进行选择。The entry point displays the chosen time, and when the user selects the entry point, a picker surface expands vertically from the middle for the user to make a selection. 时间选取器会覆盖其他 UI;它不会将其他 UI 推开。The time picker overlays other UI; it doesn't push other UI out of the way.

时间选取器展开示例

创建时间选取器Create a time picker

本示例显示如何创建带有标题的简单时间选取器。This example shows how to create a simple time picker with a header.

<TimePicker x:Name="arrivalTimePicker" Header="Arrival time"/>
TimePicker arrivalTimePicker = new TimePicker();
arrivalTimePicker.Header = "Arrival time";

生成的时间选取器如下所示:The resulting time picker looks like this:

时间选取器示例

备注

有关日期和时间值的重要信息,请参阅日期和时间控件一文中的DateTime 和日历值For important info about date and time values, see DateTime and Calendar values in the Date and time controls article.

获取示例代码Get the sample code