Hi ,
I am new to xamarin.forms
I was trying two way databinding but when it comes to binding with interger property which is nullable it doesnt update viewmodel from view
Canany one please tell me how to handle that
What I have tried:
//View
<StackLayout VerticalOptions="Center">
<Label Text="Name of the student"></Label>
<Entry Text="{Binding Person.Name, Mode=TwoWay}"></Entry>
<Label Text="Age of the person"></Label>
<Entry Text="{Binding Person.Age, Mode=TwoWay}"></Entry>
<Label Text="Last Name of the person"></Label>
<Entry Text="{Binding Person.LastName, Mode=TwoWay}"></Entry>
<Button Text="SaveTask" Command="{Binding SaveCommand}"></Button>
<Label Text="{Binding Message}" TextColor="{Binding Message, Converter={StaticResource TextToColorConverter}}"></Label>
</StackLayout>
//ViewModel
public class HomeViewModel : INotifyPropertyChanged
{
public PersonBO _person;
private string _message;
public PersonBO Person
{
get
{
return _person;
}
set
{
_person = value;
OnPropertyChanged();
}
}
public string Message
{
get { return _message; }
set
{
_message = value;
OnPropertyChanged();
}
}
public Command SaveCommand
{
get
{
return new Command(() =>
{
Message = "Your task : " + Person.Name + " ,"
+ Person.Age + "," + Person.LastName + " was sucessfully saved !";
});
}
}
public HomeViewModel()
{
Person = new PersonBO()
{
Name = "Neil",
Age = 26
};
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
//Model
public class PersonBO
{
public string Name { get; set; }
public string LastName { get; set; }
public int? Age { get; set; }
}
Here age donest get update when clicking on button