PowerApps 中的卡片控件Card control in PowerApps

提供显示窗体编辑窗体控件的单个字段的显示和编辑体验。Provides the display and editing experience for a single field of a Display form or Edit form control.


显示窗体编辑窗体控件充当用于显示和查看完整记录的容器。Display form and Edit form controls act as containers for displaying and viewing entire records. 每个容器可以容纳一组卡片控件,这些控件显示各个字段或提供更新这些字段的方法。Each container can hold a set of Card controls that display individual fields or provide a way to update those fields. 每种卡片均有一个 DataField 属性,此属性指定它所适用的记录字段。Each card has a DataField property that specifies which field of the record it works on.

预定义卡片针对不同的数据类型和用户体验定义。Predefined cards are defined for different data types and user experiences. 例如,可能存在使用文本输入控件编辑数字字段的卡片,非常适合与键盘结合使用。For example, there may be a card to edit a number field with a Text input control, which is great for use with the keyboard. 而另一种卡片可能支持使用滑块控件编辑数字。Another card might support editing a number by using a Slider control instead. 选择窗体控件后,可以在右侧窗格中基于字段轻松选择卡片。With the form control selected, you can, in the right-hand pane, easily select a card based on a field.

卡片本身包含控件。Cards themselves contain controls. 卡片的控件构成了显示和编辑单个字段的体验。The controls of a card make up the experience for displaying and editing a single field. 例如,数字卡片可能包含显示字段的显示名称的“标签”控件,以及提供字段值编辑器的“文本输入”控件。For example, a number card may consist of a Label control to provide the display name of the field and a Text input control to provide an editor for the value of the field. 卡片可能还包含显示所有验证错误的“标签”控件,以及使用常见星号指明字段为必填字段的“标签”控件。The card may also have a Label control that shows any validation errors that occur and a Label control for the common asterisk to indicate that a field is required.

可以通过以下方式自定义预定义卡片的控件:调整大小、移动、隐藏、向其添加控件及进行其他更改。You can customize the controls of a predefined card by resizing it, moving it, hiding it, adding controls to it, and making other changes. 还可以使用完全空白的卡片(即“自定义卡片”),从头开始向其添加控件。You can also start with an entirely blank card, a "custom card", to which you add controls from scratch.

默认情况下,预定义卡片处于“锁定”状态。Predefined cards are locked by default. 在锁定的卡片中,只能修改卡片的某些属性或卡片内的控件,且无法删除锁定的卡片。In a locked card, you can modify only certain properties of the card or the controls within the card, and you can't delete a locked card. 可在“高级”视图的“视图”选项卡中显示卡片锁定并解锁。You can show the card lock and unlock it on the View tab of the Advanced view. 如果属性锁定且无法修改,在其名称旁将显示一个锁定图标。If a property is locked and can't be modified, it appears with a lock icon next to its name. 解锁卡片属于高级活动,需谨慎处理,因为卡片将不再自动生成公式,且无法再次锁定卡片。Unlocking a card is an advanced activity and should be done with care, because automatic formula generation will no longer occur for the card, and you can't relock a card.

在窗体的容器内,ThisItem 记录可用且包含该记录的所有字段。Within the form's container, the ThisItem record is available and contains all the fields of the record. 例如,卡片的 Default 属性通常设置为 ThisItem。FieldName。For example, the card's Default property is often set to ThisItem.FieldName.

可以使用引用配置控件以引用卡片的属性。You can use the Parent reference to configure a control to reference the properties of a card. 例如,控件应使用 Parent.Default 从数据源读取字段的初始状态。For example, a control should use Parent.Default to read the initial state of the field from the data source. 通过使用引用(而不是直接访问所需信息),可更好地封装卡片,且可以将其更改为不同的字段而不会破坏内部公式。By using Parent instead of directly accessing the information that you want, the card is better encapsulated, and you can change it to a different field without breaking internal formulas.

有关如何自定义、解锁和创建卡片的示例,请参阅了解数据卡See Understand data cards for examples of how to customize, unlock, and create cards.

关键属性Key properties

DataField - 此卡片显示和编辑的记录中的字段名称。DataField – The name of the field within a record that this card displays and edits.

  • 指定该名称为括在双引号中的单个静态字符串(例如,“Name”),而非公式。Specify the name as a single static string that's enclosed in double quotation marks (for example, "Name"), not a formula.
  • 通过将卡片的 DataField 属性设置为空白,取消绑定卡片。Unbind a card by setting its DataField property blank. 未绑定卡片将忽略 ValidUpdate 属性。The Valid and Update properties are ignored for unbound cards.

Default - 用户更改控件前的初始值。Default – The initial value of a control before it is changed by the user.

  • 对于卡片中的每个控件,将此属性设置为 Parent.Default 以根据数据源引用字段的默认值。For each control in a card, set this property to Parent.Default to refer to the default value of the field according to the data source. 例如,将滑块的 Default 属性设置为 Parent.Default 以确保用户首先使用该滑块的泛型值。For example, set a slider's Default property to Parent.Default to ensure that the user starts with a generic value for that slider.

DisplayMode – 值可以是 Edit、View 或 Disabled。DisplayMode – Values can be Edit, View, or Disabled. 配置卡内控件是允许用户输入 (Edit)、仅显示数据 (View),还是已禁用 (Disabled)。Configures whether the control inside the card allows user input (Edit), only displays data (View) or is disabled (Disabled).

  • 通过配置此属性,可在编辑和查看表单中使用单个卡,该属性默认与表单行为相关联。Allows a single card to be used in both edit and view forms, by configuring this property, which is tied to the Form's behavior by default.
  • 在 View 模式时,子控件(如文本输入下拉列表日期选取器)将仅显示文本值,不会呈现任何交互元素或修饰。In View mode, child controls such as Text input, Drop down, Date Picker will only display the text value and will not render any interactive elements or decorations.

DisplayName - 数据源中字段的用户友好名称。DisplayName – The user friendly name for a field in a data source.

  • DataSourceInfo 函数提供数据源中的元数据。The DataSourceInfo function provides this metadata from the data source.
  • 卡片内的控件应使用 Parent.DisplayName 来引用字段的名称。Controls within the card should use Parent.DisplayName to refer to the name of the field.

Error - 验证失败时,针对该字段显示的用户友好错误消息。Error – The user friendly error message to display for this field when validation fails.

  • 调用 SubmitForm 时已设置此属性。This property is set when SubmitForm is called.
  • 该消息根据数据源的元数据和检查卡片的必需属性描述验证问题。The message describes validation problems based on the data source's metadata and checking the card's Required property.

必需 - 无论是否存在卡片,编辑数据源的字段必须包含值。Required – Whether a card, editing the field of a data source, must contain a value.

  • DataSourceInfo 函数可提供数据源中的必需元数据。The DataSourceInfo function provides the required metadata from the data source.
  • 卡片内的控件应使用 Parent.Required 来确定该卡片的字段是否必需。Controls within the card should use Parent.Required to determine whether that card's field is required.

Update - 回写到字段的数据源的值。Update – The value to write back to the data source for a field.

  • 使用此属性的公式从卡片的编辑控件中请求值,以回写到数据源。Use this property's formula to pull the values from the edit controls of the card in order to write back to the data source. 例如,将卡片的 Update 属性设为 Slider.Value,使用该卡片中的滑块的值更新数据源。For example, set a card's Update property to Slider.Value to update the data source with a value from the slider in that card.

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

WidthFit - 控件是否会自动水平变宽,以填充容器控件(如“编辑表单”控件)的所有空白空间。WidthFit – Whether a control automatically grows horizontally to fill any empty space in a container control such as an Edit form control. 如果多张数据卡将此属性设置为“true”,那么空白空间会被这些数据卡均分。If multiple cards have this property set to true, the space is divided between them. 有关详细信息,请参阅了解数据表单布局For more information, see Understand data form layout.

其他属性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.

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

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

Valid - 卡片编辑窗体控件是否包含准备好提交到数据源的有效项。Valid – Whether a Card or Edit form control contains valid entries, ready to be submitted to the data source.

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

X - 控件左边缘与其父容器(如果没有父容器,则为屏幕)左边缘之间的距离。X – The distance between the left edge of a control and the left edge of its parent container (screen if no parent container). 对于多列容器中的“数据卡”控件,此属性将确定数据卡出现在哪一列。For a Card control in a container that has multiple columns, this property determines the column in which the card appears.

Y - 控件上边缘与其父容器(如果没有父容器,则为屏幕)上边缘之间的距离。Y – The distance between the top edge of a control and the top edge of the parent container (screen if no parent container). 对于多行容器中的“数据卡”控件,此属性将确定数据卡出现在哪一行。For a Card control in a container that has multiple rows, this property determines the row in which the card appears.


有关示例,请参阅了解数据卡了解数据表单布局See Understand data cards and Understand data form layout for examples.