Exemplo n.º 1
0
        private void OnContactUpdated(ContactDetailViewModel source, Contact contact)
        {
            // Here we need to find the corresponding Contact object in our
            // ObservableCollection first.
            var contactInList = Contacts.Single(c => c.Id == contact.Id);

            contactInList.Id        = contact.Id;
            contactInList.FirstName = contact.FirstName;
            contactInList.LastName  = contact.LastName;
            contactInList.Phone     = contact.Phone;
            contactInList.Email     = contact.Email;
            contactInList.IsBlocked = contact.IsBlocked;
        }
Exemplo n.º 2
0
        public ContactDetailPage(ContactViewModel viewModel)
        {
            InitializeComponent();

            // BindingContext = viewModel;

            var contactStore = new SQLiteContactStore(DependencyService.Get <ISQLiteDb>());
            var pageService  = new PageService();

            // Note that I've pushed the responsibility of creating a
            // ContactDetailViewModel into this page. This simplifies the code
            // in the consumer of this page (ContactsPageViewModel). So, every time
            // we create a new ContactDetailPage, we don't have to worry about
            // instantiating the underlying view model.

            BindingContext = new ContactDetailViewModel(
                viewModel ?? new ContactViewModel(), contactStore, pageService);
        }
        private async Task SelectContact(ContactViewModel contact)
        {
            if (contact == null)
            {
                return;
            }

            SelectedContact = null;

            var viewModel = new ContactDetailViewModel(contact, _contactStore, _pageService);

            viewModel.ContactUpdated += (source, updatedContact) =>
            {
                contact.Id        = updatedContact.Id;
                contact.FirstName = updatedContact.FirstName;
                contact.LastName  = updatedContact.LastName;
                contact.Phone     = updatedContact.Phone;
                contact.Email     = updatedContact.Email;
                contact.IsBlocked = updatedContact.IsBlocked;
            };

            await _pageService.PushAsync(new ContactDetailPage(viewModel));
        }
 private void OnContactAdded(ContactDetailViewModel source, Contact contact)
 {
     Contacts.Add(new ContactViewModel(contact));
 }
        public ContactDetailPage(ContactDetailViewModel viewModel)
        {
            InitializeComponent();

            BindingContext = viewModel;
        }