如何将值从我的类文件传递到xaml文件

  • 本文关键字:文件 xaml xamarin
  • 更新时间 :
  • 英文 :


我正在学习Xamarin,我正在努力了解如何将值从类文件传递到.xmal文件中进行显示?是数据绑定还是其他什么。

示例:我的文件.cs

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

文件.xaml

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

我想要";myvalue";从我的类传递到我的xaml文件。

是的,数据绑定是的答案

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

您只能绑定到公共属性

public string MyValue { get; set; }
public LandingPage()
{
InitializeComponent();
MyValue = "hello world";
this.BindingContext = this;
}

最新更新