添加列表框、下拉列表或单选按钮Add a list box, a drop-down list, or radio buttons

PowerApps 提供多选和单选选项,其中包括列表框、下拉列表和单选按钮。PowerApps includes multi-select and single-select options, including a list box, a drop-down list, and radio buttons. 在本主题中,我们会添加这些控件并使用公式来生成列表。In this topic, we add these controls and use a Table formula to build the lists. 在列表中选定某项时,它会更新其他控件。When an item is selected in the list, it updates other controls.

 

必备组件Prerequisites

添加列表框Add a list box

  1. 在“插入”选项卡上,选择“控件”,然后选择“列表框”:On the Insert tab, select Controls, and then select List box:

  2. 将“列表框”控件重命名为“MyListBox”:Rename the List box control to MyListBox:

  3. 将其 Items 属性设置为下面的表达式:Set its Items property to the following expression:
    ["circle","triangle","rectangle"]

    设计器的外观与下图类似:Your designer looks similar to the following:

  4. 在“插入”选项卡上,选择“图标”,选择圆形,然后将其移到“列表框”控件下面:On the Insert tab, select Icons, select the circle, and move it under the List box control:

  5. 添加三角形和矩形,然后将这些形状在“列表框”控件下面排成一行:Add a triangle and a rectangle, and then arrange the shapes in a row under the List box control:

  6. 将以下形状的 Visible 属性设置为以下函数:Set the Visible property of the following shapes to the following functions:

    形状Shape 将 Visible 函数设置为Set Visible function to
    圆形circle If("circle" in MyListBox.SelectedItems.Value, true)
    三角形triangle If("triangle" in MyListBox.SelectedItems.Value, true)
    矩形rectangle If("rectangle" in MyListBox.SelectedItems.Value, true)
  7. 预览所创建的内容 Preview what you've created . 在“列表框”控件中选择不同的形状。Select the different shapes in the List box control. 仅显示所选的形状。Only the shape or shapes that you select appear. 按 Esc 或选择“X”返回到屏幕。Press Esc or select the X to go back to your screen.

在这些步骤中使用了表达式在“列表框”控件中创建项列表。In these steps, you used an expression to create a list of items in a List box control. 根据在“列表框”控件中所做的选择,将显示不同的形状。Depending on what you choose in the List box control, different shapes are displayed. 可以将此应用于业务中的其他元素。You can apply this to other elements within your business. 例如,可以使用“列表框”控件来显示产品图像、产品说明等等。For example, you can use a List box control to display product images, product descriptions, and so on.

添加单选按钮Add radio buttons

  1. 在“主页”选项卡上,选择“新屏幕”。On the Home tab, select New Screen.
  2. 在“插入”选项卡上,选择“控件”,然后选择“单选按钮”。On the Insert tab, select Controls, and then select Radio.

  3. 将“单选按钮”控件重命名为“Choices”,并将其 Items 属性设置为此公式:Rename the Radio control to Choices, and set its Items property to this formula:
    ["red","green","blue"]

    如有需要,可将控件大小重设为显示所有选项。If needed, resize the control to show all the options.

  4. 在“插入”选项卡上,选择“图标”,然后选择圆形。On the Insert tab, select Icons, and then select the circle.
  5. 将圆形的 Fill 属性设置为下面的函数:Set the Fill property of the circle to the following function:
    If(Choices.Selected.Value = "red", RGBA(192, 0, 0, 1), Choices.Selected.Value = "green", RGBA(0, 176, 80, 1), Choices.Selected.Value = "blue", RGBA(0, 32, 96, 1))

    在此公式中,圆形根据所选单选按钮更改其颜色。In this formula, the circle changes its color depending on which radio button you choose.

  6. 将圆形移到“单选按钮”控件下面,如此示例所示:Move the circle under the Radio control, as in this example:

  7. 预览所创建的内容:Preview what you've created: . 选中不同的单选按钮以更改圆形的颜色。Select a different radio button to change the color of the circle. 按 Esc 或选择“X”返回到屏幕。Press Esc or select the X to go back to your screen.

添加下拉列表Add a drop-down list

  1. 添加屏幕,然后添加“下拉列表”控件。Add a screen, and then add a Drop down control.

  2. 将该控件重命名为“DDChoices”,并将其 Items 属性设置为此公式:Rename the control to DDChoices, and set its Items property to this formula:
    ["red","green","blue"] ["red","green","blue"]
  3. 添加一个圆形,将其移到“下拉列表”控件下面,然后将圆形的 Fill 属性设置为此公式:Add a circle, move it below the Drop down control, and set the circle's Fill property to this formula:
    If(DDChoices.Selected.Value = "red", RGBA(192, 0, 0, 1), DDChoices.Selected.Value = "green", RGBA(0, 176, 80, 1), DDChoices.Selected.Value = "blue", RGBA(0, 32, 96, 1))
  4. 预览所创建的内容:Preview what you've created: . 选择不同选项以更改圆形的颜色。Select the different options to change the color of the circle.