Exemplo n.º 1
0
        private async void ShowContactCard_Click(object sender, RoutedEventArgs e)
        {
            Contact contact = CreatePlaceholderContact();

            // Show the contact card next to the button.
            Rect rect = MainPage.GetElementRect(sender as FrameworkElement);

            // The contact card placement can change when it is updated with more data. For improved user experience, specify placement
            // of the card so that it has space to grow and will not need to be repositioned. In this case, default placement first places
            // the card above the button because the card is small, but after the card is updated with more data, the operating system moves
            // the card below the button to fit the card's expanded size. Specifying that the contact card is placed below at the beginning
            // avoids this repositioning.
            Placement placement = Placement.Below;

            // For demonstration purposes, we ask for the Enterprise contact card.
            ContactCardOptions options = new ContactCardOptions()
            {
                HeaderKind = ContactCardHeaderKind.Enterprise
            };

            using (ContactCardDelayedDataLoader dataLoader = ContactManager.ShowDelayLoadedContactCard(contact, rect, placement, options))
            {
                if (dataLoader != null)
                {
                    // Simulate downloading more data from the network for the contact.
                    this.rootPage.NotifyUser("Simulating download...", NotifyType.StatusMessage);

                    Contact fullContact = await DownloadContactDataAsync(contact);

                    if (fullContact != null)
                    {
                        // Update the contact card with the full set of contact data.
                        dataLoader.SetData(fullContact);
                        this.rootPage.NotifyUser("Contact has been updated with downloaded data.", NotifyType.StatusMessage);
                    }
                    else
                    {
                        this.rootPage.NotifyUser("No further information available.", NotifyType.StatusMessage);
                    }
                }
                else
                {
                    this.rootPage.NotifyUser("ShowDelayLoadedContactCard is not supported by this device.", NotifyType.ErrorMessage);
                }
                // The "using" statement will dispose the dataLoader for us.
            }
        }
        /// <summary>
        /// This is the click handler for the 'Show contact card with delayed data loader' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ShowContactCardDelayLoadButton_Click(object sender, RoutedEventArgs e)
        {
            // Create contact object with small set of initial data to display.
            Contact contact = new Contact();

            contact.FirstName = "Kim";
            contact.LastName  = "Abercrombie";

            ContactEmail email = new ContactEmail();

            email.Address = "*****@*****.**";
            contact.Emails.Add(email);

            // Get the selection rect of the button pressed to show contact card.
            Rect rect = Helper.GetElementRect(sender as FrameworkElement);

            using (ContactCardDelayedDataLoader dataLoader = ContactManager.ShowDelayLoadedContactCard(
                       contact,
                       rect,
                       Windows.UI.Popups.Placement.Below // The contact card placement can change when it is updated with more data. For improved user experience, specify placement
                                                         // of the card so that it has space to grow and will not need to be repositioned. In this case, default placement first places
                                                         // the card above the button because the card is small, but after the card is updated with more data, the operating system moves
                                                         // the card below the button to fit the card's expanded size. Specifying that the contact card is placed below at the beginning
                                                         // avoids this repositioning.
                       ))
            {
                string message = "ContactManager.ShowDelayLoadedContactCard() was called.\r\n";
                this.rootPage.NotifyUser(message, NotifyType.StatusMessage);

                // Simulate downloading more data from the network for the contact.
                message += "Downloading data ...\r\n";
                this.rootPage.NotifyUser(message, NotifyType.StatusMessage);

                Contact fullContact = await DownloadContactDataAsync(contact);

                if (fullContact != null)
                {
                    // We get more data - update the contact card with the full set of contact data.
                    dataLoader.SetData(fullContact);

                    message += "ContactCardDelayedDataLoader.SetData() was called.\r\n";
                    this.rootPage.NotifyUser(message, NotifyType.StatusMessage);
                }
            }
        }