cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
seadude
Memorable Member
Memorable Member

Reference a Controls name?

Is there a way to access the name of a control?

 

Examples:

  • control 1 is named "sombrero"
  • If I copy it 100 times, I have "sombrero_1", "sombrero_2"..."sombrero_99"
  • I want to write a function for the X property of all sombreros like:
    • X = buffer.Text + sombrero.Width * Right(sombrero.ThisItem, 3)

I could be totally off here, and there is another way to this, to access the name of a control?


Thanks

4 REPLIES 4
RusselThomas
Microsoft
Microsoft

Hi seadude,

 

 

Apologies if I misunderstand you, but it seems like you're not only trying to get to a common property across multiple controls but also trying to reference a relative property of a control within one of it's properties - I'm not sure how you can do it the way you're trying to do it as I've never come across anything like a master object model you can navigate in PowerApps, including being able to reference a this instance of a control.

 

You can set all the control's X property to the same variable and then manipulate that, but if the manipulation also needs to reference a property of that specific control then I'm stumped.

 

so, eg: variable for property X;

  • Sombrero.X = varSombreroX
  • Sombrero_1.X = varSombreroX
  • ...
  • Sombrero_99.X = varSombreroX

 

To manipulate the X value for all these controls, you can then use UpdateContext() - so;

UpdateContext({varSombreroX: value})

 

will update the X property for all controls that have it, regardless of their name - but if you want "value" to be dependent on something within each specific control and therefore different for each control, (like the length of the text in that control), then I don't think you can reference it dynamically.

 

Will watch this thread with interest 🙂

 

RT

@RusselThomas, thanks for the thoughtful reply. I actually think I made a mistake in my original post...

 

The goal is:

  • sombrero_41.X = sombrero.Width + buffer.Text * <thisSombrerosNumber> -1

 

I had "+" in the original post rather than " * ".

 

You could imagine: This would be a fast way to build a grid of items on the screen. Without this, you have to go into each Control and set the X Property of EVERY ONE like this:

 

  • sombrero_41.X = sobmbrero_40.X + sombrero.Width + buffer.Text

Is there another way to self-reference a Control?

Hi seadude,

 

Not that I'm aware of 😞

 

Even in galleries, pre-populated controls that use auto-height/auto-spacing are rendered with the absolute name of the relative control it's being spaced from - and PowerApps doesn't accept strings as object references, so I'm really not sure it's possible.

 

Sorry I couldn't help - perhaps someone else knows a way, but if it turns out to be impossible, perhaps consider logging an idea on the Ideas forum? 🙂

 

Kind regards,

 

RT

 

 

 

 

@seadude, it sounds like you want to duplicate controls and have their position respond according to their name.

 

This sounds like a use case for a gallery 🙂

 

Whenever you think of duplicating things, think of the gallery. There's a few ways to go about this, I'll share an interesting one.

 

Create a table with a column that specifies the X location you want.

Insert a control--we'll call it sombrero.

Set the X property of sombrero to the column that has the X location.

Repeat for Y if you want.

Set the TemplateSize of the Gallery to 0.

 

The position of the object will be relative to the dimensions of the gallery. You can do a lot of creative things this way.

Microsoft Employee
@8bitclassroom

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,870)