private async void PairButton_Click(object sender, RoutedEventArgs e) { // Gray out the pair button and results view while pairing is in progress. resultsListView.IsEnabled = false; pairButton.IsEnabled = false; rootPage.NotifyUser("Pairing started. Please wait...", NotifyType.StatusMessage); // Get the device selected for pairing DeviceInformationDisplay deviceInfoDisp = resultsListView.SelectedItem as DeviceInformationDisplay; // Get ceremony type and protection level selections DevicePairingKinds ceremoniesSelected = GetSelectedCeremonies(); ProtectionLevelSelectorInfo protectionLevelInfo = (ProtectionLevelSelectorInfo)protectionLevelComboBox.SelectedItem; DevicePairingProtectionLevel protectionLevel = protectionLevelInfo.ProtectionLevel; DeviceInformationCustomPairing customPairing = deviceInfoDisp.DeviceInformation.Pairing.Custom; customPairing.PairingRequested += PairingRequestedHandler; DevicePairingResult result = await customPairing.PairAsync(ceremoniesSelected, protectionLevel); customPairing.PairingRequested -= PairingRequestedHandler; rootPage.NotifyUser( "Pairing result = " + result.Status.ToString(), result.Status == DevicePairingResultStatus.Paired ? NotifyType.StatusMessage : NotifyType.ErrorMessage); HidePairingPanel(); UpdatePairingButtons(); resultsListView.IsEnabled = true; }
private void UpdatePairingButtons() { DeviceInformationDisplay deviceInfoDisp = (DeviceInformationDisplay)resultsListView.SelectedItem; if (null != deviceInfoDisp && deviceInfoDisp.DeviceInformation.Pairing.CanPair && !deviceInfoDisp.DeviceInformation.Pairing.IsPaired) { pairButton.IsEnabled = true; } else { pairButton.IsEnabled = false; } if (null != deviceInfoDisp && deviceInfoDisp.DeviceInformation.Pairing.IsPaired) { unpairButton.IsEnabled = true; } else { unpairButton.IsEnabled = false; } }
private void PairButtonClicked() { DeviceInformationDisplay deviceInfoDisp = bleDeviceListView.SelectedItem as DeviceInformationDisplay; if (deviceInfoDisp != null) { App.sDeviceManager.PairWithMac(BluetoothDevices.ConvertDeviceIdType(deviceInfoDisp.Id, AddressType.Bluetooth)); } }
private void PairedDevice_SelectionChanged(object sender, SelectionChangedEventArgs e) { DeviceInformationDisplay deviceInfoDisp = pairedDeviceListView.SelectedItem as DeviceInformationDisplay; if (deviceInfoDisp != null) { ReceivedAdvertisementListBox.Items.Add($"Paired Device - {deviceInfoDisp.Name}/{deviceInfoDisp.Id}/CanPair:{deviceInfoDisp.CanPair}/IsPaired:{deviceInfoDisp.IsPaired}"); } }
private void OnDeviceListChanged(DeviceWatcher sender, string id) { // If the item being updated is currently "selected", then update the pairing buttons DeviceInformationDisplay selectedDeviceInfoDisp = (DeviceInformationDisplay)resultsListView.SelectedItem; if ((selectedDeviceInfoDisp != null) && (selectedDeviceInfoDisp.Id == id)) { UpdatePairingButtons(); } }
private void BleDevice_SelectionChanged(object sender, SelectionChangedEventArgs e) { DeviceInformationDisplay deviceInfoDisp = bleDeviceListView.SelectedItem as DeviceInformationDisplay; if (deviceInfoDisp != null) { rootPage.SelectedBleDeviceName = deviceInfoDisp.Name; rootPage.SelectedBleDeviceId = deviceInfoDisp.Id; ReceivedAdvertisementListBox.Items.Add($"BLE Device {deviceInfoDisp.Name}/{deviceInfoDisp.Id} is selected."); PairRequestButton.IsEnabled = true; } }
private async void UnpairButton_Click(object sender, RoutedEventArgs e) { // Gray out the unpair button and results view while unpairing is in progress. resultsListView.IsEnabled = false; unpairButton.IsEnabled = false; rootPage.NotifyUser("Unpairing started. Please wait...", NotifyType.StatusMessage); DeviceInformationDisplay deviceInfoDisp = resultsListView.SelectedItem as DeviceInformationDisplay; DeviceUnpairingResult dupr = await deviceInfoDisp.DeviceInformation.Pairing.UnpairAsync(); rootPage.NotifyUser( "Unpairing result = " + dupr.Status.ToString(), dupr.Status == DeviceUnpairingResultStatus.Unpaired ? NotifyType.StatusMessage : NotifyType.ErrorMessage); UpdatePairingButtons(); resultsListView.IsEnabled = true; }