web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Identify and reference...
Power Apps
Unanswered

Identify and reference Canvas app UI control at run-time, any other way except Text property

(0) ShareShare
ReportReport
Posted on by 36

What's best way to identify and reference Canvas app UI control at run-time. Is there any other way except Text property as Text property UI visible and can be changed at design or runtime. 

Categories:
I have the same question (0)
  • WiZey Profile Picture
    3,023 Moderator on at

    Hello @microsoftee ,

     

    I'm not sure what is your issue here, could you be more specific please?

     

    There isn't really a "best method" as it is the "only" method to reference a control.

     

    You can reference any control from the formula bar by typing their name. Plus, if you change the control's name at a later date, the formula is automatically updated with the new name.

  • microsoftee Profile Picture
    36 on at

    Hi, thanks for your reply.

    I'm new in Power Platform, here's my situation.

    I'm making tab control type UI, I have 3 buttons on top and OnSelect of button I'm setting global variable to track which button clicked. The example I'm following saving/matching hardcoded button Text to track which button clicked.

    Here's my question, using Text property and matching hardcoded Text need to change all the time whenever at design time or run-time I change Text property.

    Switch(
     varCurrentTab,
     "SEND ITEMS",
     btnSend.X,
     "TRAVELLING",
     btnTravel.X,
     "Find shippers",
     btnFind.X
    )

     

  • WiZey Profile Picture
    3,023 Moderator on at

    I feel like your over-complicating your case here, but as I can't see your app nor know how you managed your buttons it's hard to tell.

     

    As for your question, well of course you'd need to adapt your condition. If you change the control's text value without adjusting the hardcoded text, they will obviously mismatch later. 

  • vvshameer Profile Picture
    36 on at

    You can try using Gallery to create tabbed control, that approach wont require a hard code

     

    https://devoworx.net/best-way-to-create-power-apps-tabs-control-tabbed-form-in-powerapps/

     

  • microsoftee Profile Picture
    36 on at

    Hi,

    I'm following article step-by-step, he's using Text property to track the button selected. I'm wondering he did this just for simplicity and if there's any better more reliable way to keep track of button clicked.

     

    https://www.matthewdevaney.com/power-apps-tabbed-form-with-an-awesome-looking-design/ 

  • WiZey Profile Picture
    3,023 Moderator on at

    Another way would be to use the "Selected" property of the gallery. But using a global variable is better if you're intending to use it across multiple screens.

  • microsoftee Profile Picture
    36 on at

    Hi, thanks for helping.

    It's a good alternate you've mentioned.

    But still I want to know any reliable way in such type of situation where you want to keep track of which button was clicked.

  • WiZey Profile Picture
    3,023 Moderator on at

    If you're not using a gallery, you can put the "Set()" function in the "OnSelect" property of your buttons.

     

    WiZey_0-1679474412142.png

     

    Here I created three buttons and one label. The buttons properties are:

     

     

    OnSelect:UpdateContext({selectedButton:Self.Text})
    Color:If(Self.Text = selectedButton;RGBA(56; 96; 178; 1);Color.White)
    Fill:If(Self.Text = selectedButton;Color.White;RGBA(56; 96; 178; 1))

     

     

    And the label's properties are:

     

     

    Text:selectedButton

     

     

    When clicking on a button, it sets the variable "selectedButton" to the button's text. The "If()" in the "Color" and "Fill" properties of the buttons helps visualize which button has been selected. The label gives us an insight on the variable's value.

     

    If you're using a gallery, the formulas are a bit similar.

     

    WiZey_1-1679474597055.png

     

    The gallery's property are:

     

     

    Items:["Bouton 1";"Bouton 2";"Bouton 3"]
    OnSelect:UpdateContext({selectedButton2:Gallery19.Selected.Value})

     

     

    The buttons' properties are:

     

     

    Color:If(Self.Text = selectedButton2;RGBA(56; 96; 178; 1);Color.White)
    Fill:If(Self.Text = selectedButton2;Color.White;RGBA(56; 96; 178; 1))

     

     

    And the label's properties are:

     

     

    Text:selectedButton2

     

     

    Note that with a gallery, the button's "OnSelect" is not used. That's because the gallery already has a "OnSelect" property which we can use here whenever the user selects an item from the gallery.

    Also, I've used "UpdateContext()" in my examples, however, the variable is screen-wide and not app-wide.

     

    If you want more control on the button's text, you can set a global enum variable. This will help you set the button's text only once in your app, avoiding the case where you'll have to search for every case where the button's text value was used.

     

     

    OnStart:Set(buttons;{Button1:"Bouton 1";Button2:"Bouton 2";Button3:"Bouton 3"})

     

     

    WiZey_2-1679474945701.png

     

  • microsoftee Profile Picture
    36 on at

    Hi @WiZey ,

    in your example for code, you store Self.Text to SelectedButton variable.

    If I need to put some logic based on the button selected/clicked e.g. Button 2, I'll write code as following 

    if(SelectedButton="Button 2"...

    This was my question, once I change Text for button 2, I need to make change all places I'm comparing SelectedButton value  with hardcoded.

  • WiZey Profile Picture
    3,023 Moderator on at

    That's why I suggest to store the text in a global variable, like an enumerator you can access anywhere.

     

    App.OnStart:Set(buttons;{Button1:"Bouton 1";Button2:"Bouton 2";Button3:"Bouton 3"})

    Then use the variable in "Text" property of the button:

    WiZey_0-1679901772219.png

     

    With this, even if you must change the button's text for some reasons, all you have to do is edit the global variable "buttons" and it will automatically reflect the changes through all your screens.

     

    Instead of...
    
    Button1.Text: "Button1"
    Button1.OnSelect:UpdateContext({selectedButton:Self.Text})
    Button1.Color:If(Self.Text = selectedButton, RGBA(...), White)
    
    Use...
    
    Button1.Text: buttons.Button1
    Button1.OnSelect:UpdateContext({selectedButton:Self.Text})
    Button1.Color:If(Self.Text = selectedButton, RGBA(...), White)

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard