【发布时间】:2021-07-12 05:36:07
【问题描述】:
假设我的 .cs 文件中有一个名为 number 的变量,我想将我的 xaml 页面中的标签文本设置为 number 的值。我怎样才能做到这一点?我检查了this link,但对我没有帮助。我错过了什么吗?
cs:
public partial class OrdersPage : ContentPage
{
public string number = Methods.GetMessage("number");
public OrdersPage()
{
InitializeComponent();
Init();
}
private async void Init()
{
this.BindingContext = this;
....
}
xaml:
<Label FontSize="Subtitle">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding number}" FontAttributes="Bold"/>
<Span Text=": " FontAttributes="Bold"/>
<Span Text="{Binding PickupNo}" TextColor="{Binding Source={x:Static static:Constants.PRIMARY_COLOR}}"/>
</FormattedString>
</Label.FormattedText>
</Label>
【问题讨论】:
-
P.S:我尝试使用字符串编号 {get; set;} 但 id 也不起作用
-
您只能绑定到公共属性。
public string number是公开的,但它不是 C# 属性 -
@Jason 那么解决方案是什么?
-
使其成为公共财产。
标签: c# xaml xamarin xamarin.forms mobile