如何将值从我的 class 文件传递​​到 xaml 文件?

How to pass value from my class file to xaml file?

我正在学习 Xamarin,我正在尝试了解如何将值从我的 class 文件传递​​到 .xmal 文件以供显示?是数据绑定还是其他什么。

示例: 我的 file.cs

namespace MyApp.Views
{
    public partial class LandingPage : ContentPage
    {
        public LandingPage()
        {
           string myvalue = "hello world";
        }
     }
}

file.xaml

<StackLayout>
  <Label Text="myvalue" />
</StackLayout>

我希望“myvalue”从我​​的 class 传递到我的 xaml 文件。

是的,data binding就是答案

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

您只能绑定到 public 属性

public string MyValue { get; set; }

public LandingPage()
{
   InitializeComponent();

   MyValue = "hello world";

   this.BindingContext = this;
}