Connor
Connor

Reputation: 49

How to set the width of one element to the width of another in Xamarin?

I am using a box view to underline some text in Xamarin and I want to set the width of the box view to the width of the label

Upvotes: 0

Views: 1006

Answers (2)

Chris Tina
Chris Tina

Reputation: 55

Label has a property TextDecorations. You can set it to Underline to underline a text without using BoxView.

    <Label Text="Your Text" TextDecorations="Underline">

Upvotes: 3

Harikrishnan
Harikrishnan

Reputation: 1474

Define WidthRequest for the Label and bind that to the Box view as shown below.

<StackLayout Padding="0,10" HorizontalOptions="Center" VerticalOptions="Center" Orientation="Horizontal">
    <Button x:Name="BtnSend" Clicked="BtnSend_Clicked" Text="Send" WidthRequest="150" />

    <Label Text="Hello" BackgroundColor="Yellow" WidthRequest="{Binding WidthRequest, Source={x:Reference BtnSend}}"  />
</StackLayout>

Upvotes: 3

Related Questions