Hi, I have also some trouble setting up binding with my form. this is what I have at the moment. when debugging. the properties are always null... ive tried adding the notifypropertychanged function in the xaml.cs but this didnt work.
XAML:
``
x:Class="DestinationsApp.AddDestinyPage">
<StackLayout Margin="10,10,10,0" BindingContext="{x:Binding Destiny}"> <Label Text="Add destiny" Margin="10" HorizontalTextAlignment="Center" FontSize="Title" TextColor="Black"/> <Label Text="Country" FontSize="Title" TextColor="Black"/> <Entry x:Name="eCountry" Text="{Binding Country, Mode=OneWay}"/> <Label Text="City" FontSize="Title" TextColor="Black"/> <Entry x:Name="eCity" Text="{Binding City,Mode=OneWay}"/> <Label Text="Type" FontSize="Title" TextColor="Black"/> <Picker x:Name="pType" SelectedItem="{Binding Type, Mode=OneWay}"> <Picker.Items> <x:String>Appartment</x:String> <x:String>Hotel</x:String> <x:String>Camping</x:String> </Picker.Items> </Picker> <Button x:Name="btnAddDestiny" Text="Add destiny" Clicked="btnAddDestiny_Clicked"/> </StackLayout>
``
XAML.CS:
``
public partial class AddDestinyPage : ContentPage, INotifyPropertyChanged
{
private Destiny _Destiny;
public Destiny Destiny { get { return _Destiny; } set { _Destiny = value; OnPropertyChanged(); } } public AddDestinyPage() { InitializeComponent(); Destiny = new Destiny(); //BindingContext = Destiny; } private async void btnAddDestiny_Clicked(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(Destiny.Country) || string.IsNullOrWhiteSpace(Destiny.City) || string.IsNullOrWhiteSpace(Destiny.Type)) { } } }
``
Class:
``
public class Destiny : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string _ID;
public string ID { get { return _ID; } set { _ID = value; OnPropertyChanged(nameof(ID)); } } private string _Country; public string Country { get { return _Country; } set { _Country = value; OnPropertyChanged(nameof(Country)); } } private string _City; public string City { get { return _City; } set { _City = value; OnPropertyChanged(nameof(City)); } } private string _Type; public string Type { get { return _Type; } set { _Type = value; OnPropertyChanged(nameof(Type)); } } }
``