private async Task<IList<Contact>> SelectContactsAsync( SelectContactInteraction selectContact ) { Contract.Requires( selectContact != null ); Contract.Ensures( Contract.Result<Task<IList<Contact>>>() != null ); var commitButtonText = selectContact.DefaultCommand?.Name; var dialog = new ContactPicker(); dialog.DesiredFieldsWithContactFieldType.AddRange( selectContact.DesiredFields ); #if WINDOWS_PHONE_APP TryIfImplemented( () => dialog.SelectionMode = selectContact.DesiredFields.Any() ? ContactSelectionMode.Fields : ContactSelectionMode.Contacts ); TryIfImplemented( () => { if ( !string.IsNullOrEmpty( commitButtonText ) ) dialog.CommitButtonText = commitButtonText; } ); #else dialog.SelectionMode = selectContact.DesiredFields.Any() ? ContactSelectionMode.Fields : ContactSelectionMode.Contacts; if ( !string.IsNullOrEmpty( commitButtonText ) ) dialog.CommitButtonText = commitButtonText; #endif if ( selectContact.Multiselect ) return await dialog.PickContactsAsync(); var contacts = new List<Contact>(); var contact = await dialog.PickContactAsync(); if ( contact != null ) contacts.Add( contact ); return contacts; }
private static void InvokeCallbackCommand( SelectContactInteraction selectContact, IList<Contact> contacts ) { Contract.Requires( selectContact != null ); Contract.Requires( contacts != null ); if ( contacts.Any() ) { // set contacts and execute accept selectContact.Contacts.ReplaceAll( contacts ); selectContact.ExecuteDefaultCommand(); } else { // execute cancel selectContact.ExecuteCancelCommand(); } }
public static Task<IList<Contact>> RequestMultipleContactsAsync( this InteractionRequest<SelectContactInteraction> interactionRequest, string selectButtonText, IReadOnlyList<ContactFieldType> desiredFields ) { Arg.NotNull( interactionRequest, nameof( interactionRequest ) ); Arg.NotNull( desiredFields, nameof( desiredFields ) ); if ( string.IsNullOrEmpty( selectButtonText ) ) selectButtonText = SR.SelectCaption; var source = new TaskCompletionSource<IList<Contact>>(); SelectContactInteraction interaction = null; interaction = new SelectContactInteraction() { Multiselect = true, DefaultCommandIndex = 0, CancelCommandIndex = 1, Commands = { new NamedCommand<object>( "Select", selectButtonText, p => source.TrySetResult( interaction.Contacts ) ), new NamedCommand<object>( "Cancel", SR.CancelCaption, p => source.TrySetResult( NoContacts ) ) } }; interaction.DesiredFields.AddRange( desiredFields ); interactionRequest.Request( interaction ); return source.Task; }