PowerApps 中的日期选取器控件Date Picker control in PowerApps

用户可单击或点击以指定日期的控件。A control that the user can click or tap to specify a date.

说明Description

如果添加日期选取器控件而非文本输入控件,可帮助确保用户以正确的格式指定日期。If you add a Date Picker control instead of a Text input control, you help ensure that the user specifies a date in the correct format.

关键属性Key properties

DefaultDate - 日期控件的初始值(除非用户更改)。DefaultDate – The initial value of a date control unless the user changes it.

SelectedDate - 日期控件中当前选定的日期。SelectedDate – The date currently selected in a date control.

Format - 控件显示日期和用户指定日期所使用的文本格式。Format – The text format in which the control shows the date and the user specifies the date. 可以将此属性设置为“ShortDate”(默认)或“LongDate”,从而根据此控件的“Language”属性设置日期格式。You can set this property to ShortDate (default) or LongDate to format dates based on the Language property of this control. 若要使用相同的格式,而不考虑语言,也可以将此属性设置为表达式(如“yyyy/mm/dd”)。You can also set this property to an expression, such as yyyy/mm/dd if you want the same format regardless of language. 例如:For example:

  • 如果用户单击或点击 2017 年的最后一天,“Format”属性设置为“ShortDate”,且“Language”属性设置为“en-us”,那么此控件显示“12/31/2017”。The control shows 12/31/2017 if the user clicks or taps the last day of 2017, the Format property is set to ShortDate, and the Language property is set to en-us.
  • 如果用户单击或点击 2017 年的最后一天,“Format”属性设置为“LongDate”,且“Language”属性设置为“fr-fr”,那么此控件显示“dimanche 31 decembre 2017”。The control shows dimanche 31 decembre 2017 if the user clicks or taps the last day of 2017, the Format property is set to LongDate, and the Language property is set to fr-fr.

Language - 确定设置日期格式所使用的语言,包括月份名称。Language – Determines the language used to format dates, including names of months. 如果未指定此属性,语言将由用户设备设置决定。If this property isn't specified, the user's device setting determines the language.

其他属性Additional properties

BorderColor – 控件边框的颜色。BorderColor – The color of a control's border.

BorderStyle – 控件边框是实线虚线点线还是BorderStyle – Whether a control's border is Solid, Dashed, Dotted, or None.

BorderThickness – 控件边框的粗细。BorderThickness – The thickness of a control's border.

FocusedBorderThickness – 控件具有键盘焦点时的边框粗细。FocusedBorderThickness – The thickness of the control's border when it has keyboard focus.

Color – 控件中文本的颜色。Color – The color of text in a control.

DisplayMode – 控件是允许用户输入 (Edit)、仅显示数据 (View),还是已禁用 (Disabled)。DisplayMode – Whether the control allows user input (Edit), only displays data (View), or is disabled (Disabled).

DisabledBorderColor – 控件的 DisplayMode 属性设置为 Disabled 时,该控件边框的颜色。DisabledBorderColor – The color of a control's border if the control's DisplayMode property is set to Disabled.

DisabledColor – 控件的 DisplayMode 属性设置为 Disabled 时,该控件中的文本颜色。DisabledColor – The color of text in a control if its DisplayMode property is set to Disabled.

DisabledFill – 控件的 DisplayMode 属性设置为 Disabled 时,该控件的背景颜色。DisabledFill – The background color of a control if its DisplayMode property is set to Disabled.

EndYear - 用户可将日期选取器控件的值设为的最后一个年份。EndYear – The latest year to which the user can set value of a date-picker control.

Fill – 控件的背景颜色。Fill – The background color of a control.

Font – 文本中所显示的字体系列的名称。Font – The name of the family of fonts in which text appears.

FontWeight – 控件中文本的粗细:粗体半粗体正常细体FontWeight – The weight of the text in a control: Bold, Semibold, Normal, or Lighter.

Height – 控件上边缘和下边缘之间的距离。Height – The distance between a control's top and bottom edges.

Italic – 控件中的文本是否为斜体。Italic – Whether the text in a control is italic.

OnSelect – 用户点击或单击某个控件时应用响应的方式。OnSelect – How the app responds when the user taps or clicks a control.

PaddingBottom – 控件中的文本与该控件下边缘之间的距离。PaddingBottom – The distance between text in a control and the bottom edge of that control.

PaddingLeft - 控件中的文本与该控件的左边缘之间的距离。PaddingLeft – The distance between text in a control and the left edge of that control.

PaddingRight - 控件中的文本与该控件的右边缘之间的距离。PaddingRight – The distance between text in a control and the right edge of that control.

PaddingTop – 控件中的文本与该控件上边缘之间的距离。PaddingTop – The distance between text in a control and the top edge of that control.

Size – 控件上显示的文本的字号。Size – The font size of the text that appears on a control.

StartYear - 用户可将日期选取器控件的值设为的最早年份。StartYear – The earliest year to which the user can set the value of a date-picker control.

TabIndex - 设置为非零值时,在运行时自定义控件的选项卡顺序。TabIndex – Customizes the tab order of controls at runtime when set to a non-zero value.

Visible – 控件显示还是隐藏。Visible – Whether a control appears or is hidden.

Width – 控件左边缘和右边缘之间的距离。Width – The distance between a control's left and right edges.

X - 控件左边缘与其父容器(如果没有父容器,则为屏幕)左边缘之间的距离。X – The distance between the left edge of a control and the left edge of its parent container (screen if no parent container).

Y - 控件上边缘与其父容器(如果没有父容器,则为屏幕)上边缘之间的距离。Y – The distance between the top edge of a control and the top edge of the parent container (screen if no parent container).

Year( DateTimeValue )Year( DateTimeValue )

示例Example

  1. 添加日期选取器控件,并将其命名为 DeadlineAdd a Date Picker control, and name it Deadline.

    不知道如何添加、命名和配置控件Don't know how to add, name, and configure a control?

  2. 添加一个“标签”控件,然后将“Text”属性设置为以下公式:Add a Label control, and set its Text property to this formula:
    DateDiff(Today(), Deadline.SelectedDate) & " days to go!"DateDiff(Today(), Deadline.SelectedDate) & " days to go!"

    想要了解有关 DateDiff 函数或其他函数的详细信息?Want more information about the DateDiff function or other functions?

  3. 按 F5,在 Deadline 中选择一个日期,然后单击或点击“确定”。Press F5, choose a date in Deadline, and then click or tap OK.

    此时,“标签”控件显示今天距离所选日期还剩多少天。The Label control shows the number of days between today and the date that you chose.

  4. 若要返回到默认工作区,请按 Esc 键。To return to the default workspace, press Esc.