private async void PairingRequestedHandler( DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args) { switch (args.PairingKind) { case DevicePairingKinds.ConfirmOnly: // Windows itself will pop the confirmation dialog as part of "consent" if this is running on Desktop or Mobile // If this is an App for 'Windows IoT Core' where there is no Windows Consent UX, you may want to provide your own confirmation. args.Accept(); break; case DevicePairingKinds.DisplayPin: // We just show the PIN on this side. The ceremony is actually completed when the user enters the PIN // on the target device. We automatically accept here since we can't really "cancel" the operation // from this side. args.Accept(); // No need for a deferral since we don't need any decision from the user await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { ShowPairingPanel( "Please enter this PIN on the device you are pairing with: " + args.Pin, args.PairingKind); }); break; case DevicePairingKinds.ProvidePin: // A PIN may be shown on the target device and the user needs to enter the matching PIN on // this Windows device. Get a deferral so we can perform the async request to the user. var collectPinDeferral = args.GetDeferral(); await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { string pin = await GetPinFromUserAsync(); if (!string.IsNullOrEmpty(pin)) { args.Accept(pin); } collectPinDeferral.Complete(); }); break; case DevicePairingKinds.ProvidePasswordCredential: var collectCredentialDeferral = args.GetDeferral(); await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { var credential = await GetPasswordCredentialFromUserAsync(); if (credential != null) { args.AcceptWithPasswordCredential(credential); } collectCredentialDeferral.Complete(); }); break; case DevicePairingKinds.ConfirmPinMatch: // We show the PIN here and the user responds with whether the PIN matches what they see // on the target device. Response comes back and we set it on the PinComparePairingRequestedData // then complete the deferral. var displayMessageDeferral = args.GetDeferral(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { bool accept = await GetUserConfirmationAsync(args.Pin); if (accept) { args.Accept(); } displayMessageDeferral.Complete(); }); break; } }