Issue
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.
Solution
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;
}
Answered By - Jason
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.