private void registerReceivers() { // item added MessagingCenter.Subscribe <DataStorage, ToDoItem>(this, MessengerKeys.ItemAdded, (_, item) => { Groups[item.IsChecked ? 1 : 0].Insert(0, new ToDoItemViewModel(item)); }); // item changed MessagingCenter.Subscribe <DataStorage, ToDoItem>(this, MessengerKeys.ItemChanged, (_, item) => { for (var groupIndex = 0; groupIndex < Groups.Count; groupIndex++) { for (var itemIndex = 0; itemIndex < Groups[groupIndex].Count; itemIndex++) { if (item.Id == Groups[groupIndex][itemIndex].Item.Id) { var targetGroupIndex = item.IsChecked ? 1 : 0; if (groupIndex == targetGroupIndex) { Groups[groupIndex][itemIndex] = new ToDoItemViewModel(item); } else { Groups[groupIndex].RemoveAt(itemIndex); Groups[targetGroupIndex].Insert(0, new ToDoItemViewModel(item)); } return; } } } }); // item deleted MessagingCenter.Subscribe <DataStorage, int>(this, MessengerKeys.ItemDeleted, (_, itemId) => { for (var groupIndex = 0; groupIndex < Groups.Count; groupIndex++) { for (var itemIndex = 0; itemIndex < Groups[groupIndex].Count; itemIndex++) { if (itemId == Groups[groupIndex][itemIndex].Item.Id) { Groups[groupIndex].RemoveAt(itemIndex); return; } } } }); }
public ToDoDetailPage(ToDoItemViewModel viewModel) { BindingContext = viewModel; InitializeComponent (); }