Skip to main content

How to See the Code of a Control in Power Apps Studio

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

The formula bar shows one property at a time. View code in Power Apps Studio shows a control's whole code at once: its type and version, and the properties that aren't at their default values. It's the quickest way to check everything a control has, such as a copy that kept a property from its original.

The example below is an Add department button on a screen that lists departments, made from a copy of another screen's Refresh button.

Prerequisites​

  • An app open for editing in Power Apps Studio.

Step 1: Open View Code​

In the Tree view, hover over the control and select … (More options). Microsoft's code view page also lists right-clicking the control, in the tree view or on the screen. Select View code, at the end of the menu:

The Tree view searched for btnAddDS, with the More options menu of btnAddDS open, listing Reorder, Cut, Copy, Paste, Delete, Rename, New comment and View code

Step 2: Read the Code​

A Code dialog opens. For a button, btnAddDS, it showed:

The Code dialog for btnAddDS, showing Control ModernButton@1.0.0 and the properties AccessibleLabel, Height, Icon, Layout, LayoutMinHeight, LayoutMinWidth, OnSelect, Text, Tooltip and Width with their formulas, above Copy code and Close buttons

View code for btnAddDS
- btnAddDS:
Control: ModernButton@1.0.0
Properties:
AccessibleLabel: ="Add a department"
Height: =40
Icon: ="Add"
Layout: =If(App.ActiveScreen.Size = ScreenSize.Small, ButtonLayout.IconOnly, ButtonLayout.IconBefore)
LayoutMinHeight: =16
LayoutMinWidth: =16
OnSelect: |-
=Navigate('Edit Department Screen', ScreenTransition.None, {locDepartmentId: Blank()})
Text: ="Add department"
Tooltip: ="Add a department"
Width: =If(App.ActiveScreen.Size = ScreenSize.Small, 40, 168)
  • btnAddDS is the control's name, and ModernButton@1.0.0 its type and version: the modern button, version 1.0.0.
  • The properties listed are the ones the button changes. Microsoft's page on the source code format says only properties that differ from their default values are written, so Visible, DisplayMode and the colors aren't there.
  • Each property's value is its formula, starting with =, as in the formula bar.

For a container or a screen, the code also lists every control inside it, each in the same form.

The code can't be edited in this dialog: change properties in the formula bar or the Properties pane. Copy code copies it, to paste as a new control or to share outside Studio. Select Close when you're done.

Example: What a Copy Kept​

I made btnAddDS from a copy of a Refresh button and changed its text, icon, width and OnSelect. Reading the screen's code later, its Tooltip still said "Refresh this screen": the copy had kept it, and nothing on the canvas showed it. The fix was one property in the formula bar, "Add a department", the value in the code above.

Common Mistakes​

MistakeWhat happensDo this instead
Looking for every property in the codeProperties at their default values aren't listedUse the Properties pane for those
Typing into the code to change a propertyThe dialog doesn't take editsChange it in the formula bar
Reading only the properties you changed after copying a controlValues the copy kept go unnoticedRead the copy's code once

FAQ​

Can I see the code of the whole app?​

Microsoft's code view page says you can't view the code for the App object. Screens and controls work, and a screen's code includes everything on it.

How do I find something in a long piece of code?​

Click in the code and press Ctrl+F, as Microsoft's page suggests.

Conclusion​

More options → View code shows a control's type and version and every property that isn't at its default, in one place: a quick check after copying controls or before sharing one.

Additional Resources​