コード例 #1
0
        //when a contact is selected from the list
        async void Contact_Selected(object sender, SelectedItemChangedEventArgs e)
        {
            if (contactList.SelectedItem == null)
            {
                return;
            }

            var selectedContact = e.SelectedItem as Contact;

            //make sure it's unselected when you go back to the main list
            contactList.SelectedItem = null;

            //subscribe to the ContactUpdated event
            var page = new ContactDetailsPage(selectedContact);

            page.ContactUpdated += (source, contact) =>
            {             //update all the properties of the contact
                selectedContact.Id        = contact.Id;
                selectedContact.FirstName = contact.FirstName;
                selectedContact.LastName  = contact.LastName;
                selectedContact.Phone     = contact.Phone;
                selectedContact.Email     = contact.Email;
                selectedContact.IsBlocked = contact.IsBlocked;
            };

            //after all that, show the contact details page
            await Navigation.PushAsync(page);
        }
コード例 #2
0
        //When Add button in toolbar is clicked - OnAddContact
        async void OnAddContact(object sender, EventArgs e)
        {
            var page = new ContactDetailsPage(new Contact());

            //subscribe to the ContactAdded event delegated by EventHandler<Contact> in ContactDetailsPage.xaml.cs
            page.ContactAdded += (source, contact) => _contacts.Add(contact);
            //navigate to page once contact is added
            await Navigation.PushAsync(page);
        }