[英]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 非常感谢
You can achieve this using FormattedText property on Label 您可以使用Label上的FormattedText属性来实现此目的
<Label>
<Label.FormattedText>
<FormattedString>
<Span Text="Hello, this is ">
<Span Text="{Binding name}">
</FormattedString>
</Label.FormattedText>
</Label>
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.