Beispiel #1
0
 private void RegisterForMessages()
 {
     Messenger.Default.Register<NotificationMessage<ItemModel>>(this, message =>
         {
             if (message.Notification == Notifications.NotifyItemAdded)
             {
                 ItemViewModel newItem = new ItemViewModel(message.Content);
                 _items.Add(newItem);
             }
             else if (message.Notification == Notifications.NotifyItemDeleted)
             {
                 ItemViewModel itemVM = _items.Where(i => i.Item.ID == message.Content.ID).FirstOrDefault();
                 if (itemVM != null)
                 {
                     SelectedItem = null;
                     _items.Remove(itemVM);
                     itemVM.Cleanup();
                 }
             }
             else if (message.Notification == Notifications.NotifyItemSaved)
             {
                 ItemViewModel itemVM = _items.Where(i => i.Item.ID == message.Content.ID).FirstOrDefault();
                 if (itemVM != null)
                 {
                     SelectedItem = null;
                     _items[_items.IndexOf(itemVM)] = new ItemViewModel(message.Content);
                     itemVM.Cleanup();
                     itemVM = null;
                 }
             }
             else if (message.Notification == Commands.SelectItem)
             {
                 if (CommandSelect.CanExecute(null))
                     CommandSelect.Execute(null);
             }
         });
 }
Beispiel #2
0
        private void BuildItemsCollection()
        {
            if (_items == null)
                _items = new ObservableCollection<ItemViewModel>();
            else
                _items.Clear();

            _itemService.GetItems().ToList().ForEach(item =>
                {
                    ItemViewModel itemVM = new ItemViewModel(item);
                    _items.Add(itemVM);
                });
        }