예제 #1
0
        async Task PlatformUnpin(NGContact contact)
        {
            var pinnedContactManager = PinnedContactManager.GetDefault();
            var winContact           = contact.ToContact();

            if (pinnedContactManager.IsContactPinned(winContact, PinnedContactSurface.Taskbar))
            {
                await pinnedContactManager.RequestUnpinContactAsync(winContact, PinnedContactSurface.Taskbar);
            }
        }
예제 #2
0
        //固定联系人
        public static async void PinContact(Contact contact)
        {
            //前面应放置API版本检查代码,仅能实装于16299
            if (await checkContactAsync(contact))
            {
                return;
            }
            await addContactAsync(contact);

            PinnedContactManager contactManager = PinnedContactManager.GetDefault();
            await contactManager.RequestPinContactAsync(contact, PinnedContactSurface.Taskbar);
        }
예제 #3
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);
            }
        }
예제 #4
0
        public static async void UnpinContact(Contact contact)
        {
            //前面应放置API版本检查代码,仅能实装于16299
            if (!(await checkContactAsync(contact)))
            {
                return;
            }
            PinnedContactManager contactManager = PinnedContactManager.GetDefault();
            var contactList = await getContactListAsync();

            await contactManager.RequestUnpinContactAsync(await contactList.GetContactFromRemoteIdAsync(contact.RemoteId), PinnedContactSurface.Taskbar);

            await deleteContactAsync(contact);
        }
        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);
                    }
                }
            }
        }
예제 #6
0
        async Task PlatformPin(NGContact contact)
        {
            var pinnedContactManager = PinnedContactManager.GetDefault();

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

            var winContact = contact.ToContact();

            if (pinnedContactManager.IsContactPinned(winContact, PinnedContactSurface.Taskbar))
            {
                // Contact is already pinned
                return;
            }

            await pinnedContactManager.RequestPinContactAsync(winContact, PinnedContactSurface.Taskbar);
        }
예제 #7
0
        private async void Cleanup_Click(object sender, RoutedEventArgs e)
        {
            ContactList list = await GetContactListAsync();

            Contact contact = await list.GetContactFromRemoteIdAsync(Constants.ContactRemoteId);

            if (contact != null)
            {
                // Request unpin
                if (!await PinnedContactManager.GetDefault().RequestUnpinContactAsync(contact, PinnedContactSurface.Taskbar))
                {
                    // User decided to keep the contact on the taskbar.
                    // Don't delete the contact after all.
                    return;
                }
            }

            // The contact is unpinned (or doesn't exist). Clean up the contact list.
            await list.DeleteAsync();
        }
예제 #8
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;
            }
        }
예제 #9
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;
            }
        }
예제 #10
0
 private async Task PinAContact(Contact contact)
 {
     PinnedContactManager pinnedContactManager = PinnedContactManager.GetDefault();
     await pinnedContactManager.RequestPinContactAsync(contact, PinnedContactSurface.Taskbar);
 }