Пример #1
0
        private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var contact = e.SelectedItem as Contact;

            Detail = new ContactDetailPage(contact);

            IsPresented = false; // IsMasterPresented
        }
Пример #2
0
        void Handle_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)
            {
                return;
            }
            var contact = e.SelectedItem as Contact;

            Detail = new ContactDetailPage(contact);
        }
Пример #3
0
        private async void OnAddContact(object sender, EventArgs e)
        {
            var page = new ContactDetailPage(new ContactBook());

            page.AddContactHandler += async(source, contact) =>
            {
                await _service.AddContact(contact);
            };

            await Navigation.PushAsync(page);
        }
Пример #4
0
        async void OnAddContact(object sender, System.EventArgs e)
        {
            var page = new ContactDetailPage(new Contact());

            // We can subscribe to the ContactAdded event using a lambda expression.
            // If you're not familiar with this syntax, watch my C# Advanced course.
            page.ContactAdded += (source, contact) =>
            {
                // ContactAdded event is raised when the user taps the Done button.
                // Here, we get notified and add this contact to our
                // ObservableCollection.
                _contacts.Add(contact);
            };

            await Navigation.PushAsync(page);
        }
Пример #5
0
        async void OnContactSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
        {
            // We need to check if SelectedItem is null because further below
            // we de-select the selected item. This will raise another ItemSelected
            // event, so this method will be called straight away. If we don't
            // check for null here, we'll get a NullReferenceException.
            if (contacts.SelectedItem == null)
            {
                return;
            }

            var selectedContact = e.SelectedItem as Contact;

            // We de-select the selected item, so when we come back to the Contacts
            // page we can tap it again and navigate to ContactDetail.
            contacts.SelectedItem = null;

            var page = new ContactDetailPage(selectedContact);

            page.ContactUpdated += (source, contact) =>
            {
                // When the target page raises ContactUpdated event, we get
                // notified and update properties of the selected contact.
                // Here we are dealing with a small class with only a few
                // properties. If working with a larger class, you may want
                // to look at AutoMapper, which is a convention-based mapping
                // tool.
                selectedContact.Id        = contact.Id;
                selectedContact.FirstName = contact.FirstName;
                selectedContact.LastName  = contact.LastName;
                selectedContact.Phone     = contact.Phone;
                selectedContact.Email     = contact.Email;
                selectedContact.IsBlocked = contact.IsBlocked;
            };

            await Navigation.PushAsync(page);
        }
Пример #6
0
        private async void OnContactSelected(object sender, ItemTappedEventArgs e)
        {
            // We need to check if SelectedItem is null because further below
            // we de-select the selected item. This will raise another ItemSelected
            // event, so this method will be called straight away. If we don't
            // check for null here, we'll get a NullReferenceException.
            if (listView.SelectedItem == null)
            {
                return;
            }

            var selectedContact = e.Item as ContactBook;

            // We de-select the selected item, so when we come back to the Contacts
            // page we can tap it again and navigate to ContactDetail.
            listView.SelectedItem = null;

            var page = new ContactDetailPage(selectedContact);

            page.UpdateContactHandler += async(source, contact) =>
            {
                var updated = await _service.UpdateContact(contact);

                if (updated)
                {
                    selectedContact.Id        = contact.Id;
                    selectedContact.FirstName = contact.FirstName;
                    selectedContact.LastName  = contact.LastName;
                    selectedContact.Phone     = contact.Phone;
                    selectedContact.Email     = contact.Email;
                    selectedContact.Blocked   = contact.Blocked;
                }
            };

            await Navigation.PushAsync(page);
        }