コード例 #1
0
        public ItemsViewModel()
        {
            Title            = "Browse";
            Notes            = new ObservableCollection <Note>();
            LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());

            // Handle "SaveNote" message
            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "SaveNote",
                                                             async(sender, note) => {
                // Add note to collection - will automatically refresh data binding
                Notes.Add(note);
                // Add to data store
                await PluralsightDataStore.AddNoteAsync(note);
            });

            // Handle "UpdateNote" message
            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "UpdateNote",
                                                             async(sender, note) => {
                // Update note in data store
                await PluralsightDataStore.UpdateNoteAsync(note);
                // Modifying a member (our note) within an ObservableCollection
                //  does not automatically refresh data binding .. so explicitly
                //  repopulate the collection
                await ExecuteLoadItemsCommand();
            });

            /*
             * MessagingCenter.Subscribe<NewItemPage, Item>(this, "AddItem", async (obj, item) =>
             * {
             *  var newItem = item as Item;
             *  Items.Add(newItem);
             *  await DataStore.AddItemAsync(newItem);
             * });
             */
        }
コード例 #2
0
        public ItemsViewModel()
        {
            Title            = "Browse";
            Notes            = new ObservableCollection <Note>();
            LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());

            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "SaveNote",
                                                             async(sender, note) => {
                Notes.Add(note);
                await PluralsightDataStore.AddNoteAsync(note);
            });
        }
コード例 #3
0
        public ItemsViewModel()
        {
            Title            = "Browse";
            Notes            = new ObservableCollection <Note>();
            LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());

            //step 7 subscribe to message
            // he throws in an lambda with two outs in the bottome of the 9th
            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "SaveNote",
                                                             async(sender, note) => {
                Notes.Add(note);
                await PluralsightDataStore.AddNoteAsync(note);
            });
        }
コード例 #4
0
        public ItemsViewModel()
        {
            Title            = "Browse";
            Notes            = new ObservableCollection <Note>();
            LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());

            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "SaveNote", async(sender, note) =>
            {
                var newNote = note as Note;
                Notes.Add(newNote);
                await PluralsightDataStore.AddNoteAsync(newNote);
            });

            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "UpdateNote",
                                                             async(sender, note) => {
                // Update note in data store
                await PluralsightDataStore.UpdateNoteAsync(note);
                // Modifying a member (our note) within an ObservableCollection
                //  does not automatically refresh data binding .. so explicitly
                //  repopulate the collection
                await ExecuteLoadItemsCommand();
            });
        }