0
votes

Is is possible to get an event when an item in the collection bound to a Xamarin Forms listview changes? For example my object has a Date field which is bound to a label in a ViewCell. I would like an event fired when the Date is changed. Our object implements INotifyPropertyChanged so the listview updates properly. I can manually subscribe to the OnPropertyChanged event of each item but I'm hoping their is an easier way.

Thanks.

1

1 Answers

-1
votes

There are triggers in Xamarin.Forms. It seems like an event trigger will do what you need. For example:

<EventTrigger Event="TextChanged">
    <local:NumericValidationTriggerAction />
</EventTrigger>

public class NumericValidationTriggerAction : TriggerAction<Entry>
{
    protected override void Invoke (Entry entry)
    {
        double result;
        bool isValid = Double.TryParse (entry.Text, out result);
        entry.TextColor = isValid ? Color.Default : Color.Red;
    }
}

You can find more information about triggers here

See this example for deleting an object when it is selected from a list view.

private MyItemsViewModel _myItemsViewModel;

private void MyItemsListView_ItemSelected(object sender,    SelectedItemChangedEventArgs e)
{
    MyItem item = (MyItem)e.SelectedItem;

    if (item == null)
        return;

    // remove the item from the ObservableCollection
    _myItemsViewModel.Items.Remove(item);
}