Xaml 简单Xamarin在代码隐藏中形成文本绑定不起作用

Xaml 简单Xamarin在代码隐藏中形成文本绑定不起作用,xaml,xamarin,Xaml,Xamarin,我有一个非常简单的代码示例来测试数据绑定的一个方面。然而,我无法让它发挥作用,我希望有人能指出我做错了什么 在cs代码隐藏文件中,我有以下内容: string textSample = "This is a test!"; BindingContext = this; 在xaml文件中: <Label Text = "{Binding Path=textSample}" /> 当我运行代码时,标签不会显示任何内容 我显然错过了什么,但我看不出是什么 提前感谢您的帮助您只能绑定

我有一个非常简单的代码示例来测试数据绑定的一个方面。然而,我无法让它发挥作用,我希望有人能指出我做错了什么

在cs代码隐藏文件中,我有以下内容:

string textSample = "This is a test!";
BindingContext = this;
在xaml文件中:

<Label Text = "{Binding Path=textSample}" />

当我运行代码时,标签不会显示任何内容

我显然错过了什么,但我看不出是什么


提前感谢您的帮助

您只能绑定到公共
属性

public string textSample { get { return "This is a test!"; }};
BindingContext = this;
不需要路径:

<Label Text = "{Binding textSample}" />

另一种方法

public string textSample {get;set;} = "This is a test!";