I am struggling with DataBindings. I have a ListView (Displays Correctly) With items and I need to be able to edit the items in the list.
I select an item which opens a modal (works fine) with the information of the selected item (works fine). When I click save, the item is not updated - The display is not updated, but if I select the item again, the data is correctly held.
I have the following object:
public class Investigation : IDisposable
{
public List<InjuredPerson> InjuredPersonnel { get; set; }
...
}
My ViewModel is like this:
public class InvestigateUtilityDamagesViewModel : INotifyPropertyChanged
{
Investigation investigation;
private InvestigateDamages damage;
public event PropertyChangedEventHandler PropertyChanged;
public InvestigateUtilityDamagesViewModel(InvestigateDamages damage)
{
this.damage = damage;
Investigation = new Investigation();
Investigation.DamageID = damage.DamageID;
Investigation.InjuredPersonnel = damage.DamageDetails.InjuredPersonnel;
}
public Investigation Investigation
{
get { return investigation; }
set
{
if (investigation == value)
{
return;
}
investigation = value;
OnPropertyChanged("Investigation");
}
}
void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
SaveInvestigation();
}
}
The XAML:
<ListView ItemsSource="{Binding Investigation.InjuredPersonnel, Mode=TwoWay}">
...
The page which updates Information sends a Message like so: (works fine)
MessagingCenter.Send<EditInjuredPerson, InjuredPerson>(this, "InjuredPersonEdited", _injuredPerson);
And the receiving side (works fine)
private void SaveInjuredPerson(EditInjuredPerson sender, InjuredPerson InjuredPerson)
{
var Injured = this.FindByName<ListView>("listInjuries").SelectedItem as InjuredPerson;
if (Injured != null)
{
Injured.Name = InjuredPerson.Name;
Injured.Position = InjuredPerson.Position;
Injured.ContactNumber = InjuredPerson.ContactNumber;
Injured.Injury = InjuredPerson.Injury;
Injured.NextOfKinName = InjuredPerson.NextOfKinName;
Injured.NextOfKinNumber = InjuredPerson.NextOfKinNumber;
}
}