Reputation: 1239
I'm learning Xamarin, and I'm trying to understand how can I pass a value from my class file to a .xmal file for display? Is that data binding or something else.
Example: My file.cs
namespace MyApp.Views
{
public partial class LandingPage : ContentPage
{
public LandingPage()
{
string myvalue = "hello world";
}
}
}
file.xaml
<StackLayout>
<Label Text="myvalue" />
</StackLayout>
I want the "myvalue" to pass from my class to my xaml file.
Upvotes: 1
Views: 272
Reputation: 89169
yes, data binding is the answer
<Label Text="{Binding MyValue}" />
you can only bind to public properties
public string MyValue { get; set; }
public LandingPage()
{
InitializeComponent();
MyValue = "hello world";
this.BindingContext = this;
}
Upvotes: 2