Reputation: 1345
Looks like I cant understand how exacly mvvm pattern works in xamarin.forms application. I want to make simple hello world application and its how I am doing this.
ViewModel
namespace HelloWorldApp.ViewModels
{
public class MainViewModel : INotifyPropertyChanged
{
private string _hello;
private string hello
{
get { return _hello; }
set
{
_hello = value;
OnPropertyChanged();
}
}
public MainViewModel() {
hello = "Hello world";
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
View
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SkanerDetali.Views.LoginPage"
xmlns:ViewModels="clr-namespace:HelloWorldApp.ViewModels;assembly=HelloWorldApp">
<ContentPage.BindingContext>
<ViewModels:MainViewModel />
</ContentPage.BindingContext>
<StackLayout>
<Label Text="{Binding hello}" />
</StackLayout>
</ContentPage>
I cant figure it out what am I missing.. Any help would be highly appreciate
Upvotes: 0
Views: 187
Reputation: 3216
Your hello
property needs to be public.
public class MainViewModel : INotifyPropertyChanged
{
private string _hello;
public string hello
{
get { return _hello; }
set
{
_hello = value;
OnPropertyChanged();
}
}
...
}
Upvotes: 3