PowerApps 中的卡片控制項Card control in PowerApps

提供顯示表單編輯表單控制項的單一欄位的顯示和編輯體驗。Provides the display and editing experience for a single field of a Display form or Edit form control.

說明Description

顯示表單編輯表單控制項做為顯示和檢視整個記錄的容器。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.FieldNameFor example, the card's Default property is often set to ThisItem.FieldName.

您可以使用 Parent參考,來設定控制項以參考卡片的內容。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. 使用 Parent 而非直接存取您想要的資訊,可更適當地封裝卡片,而且您可以將它變更為不同的欄位,而不中斷內部公式。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 – 值可以是編輯、檢視停用DisplayMode – Values can be Edit, View, or 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.
  • 檢視模式中,子控制項 (例如文字輸入下拉式清單日期選擇器) 只會顯示文字值,而不會呈現任何互動項目或裝飾。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.
  • 此訊息會根據資料來源的中繼資料,並檢查卡片的 Required 屬性,來描述驗證問題。The message describes validation problems based on the data source's metadata and checking the card's Required property.

Required – 編輯資料來源的欄位的卡片是否必須包含值。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.

範例Examples

請參閱了解資料卡了解資料表單版面配置以取得範例。See Understand data cards and Understand data form layout for examples.