Drake
Drake

Reputation: 2713

Set width to be the same as another control

In my Xamarin.Forms application, I have an Image and a Label:

<Image x:Name="myImg"/>
<Label x:Name="myLabel"/>

I want the width of the Image to be the same as the width of the Label (the text of the Label is determined at runtime). How can I do this?

Upvotes: 2

Views: 391

Answers (1)

Max Hampton
Max Hampton

Reputation: 1304

You should be able to accomplish this by binding the Image's WidthRequest to the Label's Width property.

<Image x:Name="myImg" WidthRequest="{Binding Source={x:Reference myLabel}, Path=Width}" />
<Label x:Name="myLabel" />

Upvotes: 5

Related Questions