0

I am new to xamarin, i hope someone can help me with this:

I have a sinple page with entry fields and data binding.

I have page A with a listview. When I click on an item, I get redirected to page B which has the form elements.

 async void LvData_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem != null)
            {
                var secondPage = new ProfileDataPage();
                secondPage.BindingContext = e.SelectedItem;
                await Navigation.PushAsync(secondPage);
            }
        }

This works, and in page B the fields are filled with the right data.

So now I change the value of an entry field. Then I click on the Save Button and I do something like this (profileData = BindingContext object):

 profileData.Height = Functions.ToNullableDouble(Height.Text);
profileData.Weight = Functions.ToNullableDouble(Weight.Text);
etc...

Doesn't the BindingContext know somehow that the value of the entry has changed, and I can just send the BindingContext object to my web api for save, update and so on?

Thank you very much.

JYB
  • 15
  • 5
  • You need to bind your entry text property to the profileData field you want to be updated by. I strongly advise you to check how binding works in XF and check binding modes that are available. Also, check INotifyPropertyChanged. – Umar3x Oct 31 '19 at 00:08
  • as Umar3x said,you could check your model of profileData,whether it implements `INotifyPropertyChanged` ? – Leo Zhu Oct 31 '19 at 01:47
  • Thx, I will look at this. Do i need INotifyPropertyChanged for every field or can I do it for the whole class at once? You have any good link for me to read into it? Thank you very much! – JYB Oct 31 '19 at 01:52
  • @JYB you could check below – Leo Zhu Oct 31 '19 at 02:03

2 Answers2

0

for example,here is a mode:

class MyData : INotifyPropertyChanged
{
    string height;
    string weight;
    public MyData(string height,string weight)
    {
        this.height= height;
        this.weight= weight;
    }

    public string Height
    {
        set
        {
            if (height!= value)
            {
                height= value;
                OnPropertyChanged("Height");

            }
        }
        get
        {
            return height;
        }
    }
   public string Weight
    {
        set
        {
            if (weight!= value)
            {
                weight= value;
                OnPropertyChanged("Weight");

            }
        }
        get
        {
            return weight;
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

you could refer to Binding Mode

Leo Zhu
  • 15,726
  • 1
  • 7
  • 23
0

So I tried your solutions, which helped, but only after I have update my VS, all the nuget packages and so on..

came to this idea by this post: Link

I have no idea why this was necessary, but it works now!

Thank you!

JYB
  • 15
  • 5