S Kirchner
S Kirchner

Reputation: 123

Xamarin Binding and normal text in a label

is there a posibility to have a label, with a "standart" text AND a binding content? this is what i´m looking for:

 <Label Text="Hello, this is {Binding name}"/> 

but this doesnt work. i know, i could make it like this:

  <Label Text="Hello, this is "/>
  <Label Text="{Binding name}"/>

but i would really like to do it in only one label, because if there's a wordwrap, it doesnt look that well.

thanks a lot

Upvotes: 0

Views: 400

Answers (2)

Woj
Woj

Reputation: 833

You should do it in code, so something like this.

private string _name;
public string Name
{
get
{
return String.Format("Hello, this is {0}", _name);
}
set
{
_name = value;
RaisePropertyChanged("Name"); //bear in mind this is depended on MVVM framework you are using
}
}

Upvotes: 1

Ranga
Ranga

Reputation: 1108

You can achieve this using FormattedText property on Label

<Label>
    <Label.FormattedText>
        <FormattedString>
            <Span Text="Hello, this is ">
            <Span Text="{Binding name}">
        </FormattedString>
    </Label.FormattedText>
</Label>

Upvotes: 1

Related Questions