Ejemplo n.º 1
0
        private async void Pin_Click(object sender, RoutedEventArgs e)
        {
            // Get the PinnedContactManager for the current user.
            PinnedContactManager pinnedContactManager = PinnedContactManager.GetDefault();

            // Check whether pinning to the taskbar is supported.
            if (!pinnedContactManager.IsPinSurfaceSupported(PinnedContactSurface.Taskbar))
            {
                // If not, then there is nothing for this program to do.
                rootPage.NotifyUser("The system does not support pinning contacts to the taskbar.", NotifyType.ErrorMessage);
                return;
            }

            // Get the contact list for this app.
            ContactList list = await GetContactListAsync();

            // Check if the sample contact already exists.
            Contact contact = await list.GetContactFromRemoteIdAsync(Constants.ContactRemoteId);

            if (contact == null)
            {
                // Create the sample contact.
                contact           = new Contact();
                contact.FirstName = "John";
                contact.LastName  = "Doe";
                contact.RemoteId  = Constants.ContactRemoteId;
                contact.Emails.Add(new ContactEmail {
                    Address = Constants.ContactEmail
                });
                contact.Phones.Add(new ContactPhone {
                    Number = Constants.ContactPhone
                });
                contact.SourceDisplayPicture = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/LandscapeImage20.jpg"));
                await list.SaveContactAsync(contact);
            }

            // Pin the contact to the taskbar.
            if (!await pinnedContactManager.RequestPinContactAsync(contact, PinnedContactSurface.Taskbar))
            {
                // Contact was not pinned.
                return;
            }

            // It may not be obvious to the user that a contact was pinned if it goes into the overflow.
            // If it looks like we may have gone into the overflow, notify the user that the pin was successful
            // and the contact can still receive notifications.
            if ((await pinnedContactManager.GetPinnedContactIdsAsync()).ContactIds.Count > 3)
            {
                rootPage.NotifyUser("The contact was pinned, but may appear in the overflow. Contacts in the overflow can still receive notifications.", NotifyType.StatusMessage);
            }
        }
Ejemplo n.º 2
0
        private async void ContactGrid_ContextRequested(UIElement sender, ContextRequestedEventArgs args)
        {
            _pinnedContactManager = PinnedContactManager.GetDefault();

            if (PinnedContactManager.IsSupported() && _pinnedContactManager.IsPinSurfaceSupported(PinnedContactSurface.Taskbar))
            {
                Grid       grid       = sender as Grid;
                AppContact appContact = grid.DataContext as AppContact;

                if (appContact != null)
                {
                    MenuFlyout menuFlyout = new MenuFlyout();
                    menuFlyout.Closed += MenuFlyout_Closed;

                    string menuText = $"{Constants.CONTACT_CONTEXT_MENU_TEXT_PIN} {appContact.FirstName}";
                    string menuTag  = Constants.CONTACT_CONTEXT_MENU_TAG_PIN;

                    Contact contactToPinUnpin = await GetAggregateContactFromAppContactAsync(appContact);

                    if (_pinnedContactManager.IsContactPinned(contactToPinUnpin, PinnedContactSurface.Taskbar))
                    {
                        menuText = $"{Constants.CONTACT_CONTEXT_MENU_TEXT_UNPIN} {appContact.FirstName}";
                        menuTag  = Constants.CONTACT_CONTEXT_MENU_TAG_UNPIN;
                    }

                    var menuFlyoutItem = new MenuFlyoutItem
                    {
                        Text = menuText,
                        Tag  = menuTag
                    };

                    menuFlyoutItem.Click += MenuFlyoutItem_Click;
                    menuFlyout.Items.Add(menuFlyoutItem);

                    grid.ContextFlyout = menuFlyout;

                    Point point;
                    bool  succeeded = args.TryGetPosition(grid, out point);

                    if (succeeded)
                    {
                        menuFlyout.ShowAt(grid, point);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private async Task PinContactAsync(Contact contact)
        {
            // Get the PinnedContactManager for the current user.
            PinnedContactManager pinnedContactManager = PinnedContactManager.GetDefault();

            // Check whether pinning to the taskbar is supported.
            if (!pinnedContactManager.IsPinSurfaceSupported(PinnedContactSurface.Taskbar))
            {
                // If not, then there is nothing for this program to do.
                rootPage.NotifyUser("The system does not support pinning contacts to the taskbar.", NotifyType.ErrorMessage);
                return;
            }

            // Pin the contact to the taskbar.
            if (!await pinnedContactManager.RequestPinContactAsync(contact, PinnedContactSurface.Taskbar))
            {
                // Contact was not pinned.
                return;
            }
        }
Ejemplo n.º 4
0
        private async void CustomerSupport_Click(object sender, RoutedEventArgs e)
        {
            // Get the PinnedContactManager for the current user.
            PinnedContactManager pinnedContactManager = PinnedContactManager.GetDefault();

            // Check whether pinning to the taskbar is supported.
            if (!pinnedContactManager.IsPinSurfaceSupported(PinnedContactSurface.Taskbar))
            {
                return;
            }

            // Get the contact list for this app.
            ContactList list = await GetContactListAsync();

            // Check if the sample contact already exists.
            Contact contact = await list.GetContactFromRemoteIdAsync(Constants.ContactRemoteId);


            if (contact == null)
            {
                // Create the sample contact.
                contact           = new Contact();
                contact.FirstName = "Clippy";
                contact.LastName  = "";
                contact.RemoteId  = Constants.ContactRemoteId;
                contact.Emails.Add(new ContactEmail {
                    Address = Constants.ContactEmail
                });
                contact.Phones.Add(new ContactPhone {
                    Number = Constants.ContactPhone
                });
                contact.SourceDisplayPicture = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/clippy.jpg"));

                await list.SaveContactAsync(contact);
            }

            if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
            {
                // Create a new contact annotation
                ContactAnnotation annotation = new ContactAnnotation();
                annotation.ContactId = contact.Id;

                // Add appId and contact panel support to the annotation
                String appId = "d9714431-a083-4f7c-a89f-fe7a38f759e4_75cr2b68sm664!App";
                annotation.ProviderProperties.Add("ContactPanelAppID", appId);
                annotation.SupportedOperations = ContactAnnotationOperations.ContactProfile;

                // Save annotation to contact annotation list
                // Windows.ApplicationModel.Contacts.ContactAnnotationList
                var annotationList = await GetContactAnnotationList();

                await annotationList.TrySaveAnnotationAsync(annotation);
            }

            // Pin the contact to the taskbar.
            if (!await pinnedContactManager.RequestPinContactAsync(contact, PinnedContactSurface.Taskbar))
            {
                // Contact was not pinned.
                return;
            }
        }