[英]Xamarin Binding and normal text in a label
是否可以使用帶有“標准”文本和綁定內容的標簽? 這是我在尋找的東西:
<Label Text="Hello, this is {Binding name}"/>
但這不起作用。 我知道,我可以這樣:
<Label Text="Hello, this is "/>
<Label Text="{Binding name}"/>
但是我真的只想在一個標簽中做,因為如果有自動換行,它看起來就不會那么好。
非常感謝
您可以使用Label上的FormattedText屬性來實現此目的
<Label>
<Label.FormattedText>
<FormattedString>
<Span Text="Hello, this is ">
<Span Text="{Binding name}">
</FormattedString>
</Label.FormattedText>
</Label>
您應該在代碼中執行此操作,因此應如下所示。
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.