private async void SelectButton_Click(object sender, RoutedEventArgs e) { var item = (ListBoxItem)DisplaysListBox.SelectedValue; if (item != null) { SelectButton.IsEnabled = false; var name = (string)item.Content; var deviceId = (string)item.Tag; using (ClaimedLineDisplay lineDisplay = await ClaimedLineDisplay.FromIdAsync(deviceId)) { if (lineDisplay != null) { await lineDisplay.DefaultWindow.TryClearTextAsync(); rootPage.NotifyUser($"Selected: {name}", NotifyType.StatusMessage); // Save this device ID for other scenarios. rootPage.LineDisplayId = deviceId; } else { rootPage.NotifyUser("Unable to claim the Line Display", NotifyType.ErrorMessage); } } SelectButton.IsEnabled = true; } }
private async void DisplayTextButton_Click(object sender, RoutedEventArgs e) { string text = "Hello from UWP"; using (ClaimedLineDisplay lineDisplay = await ClaimedLineDisplay.FromIdAsync(rootPage.LineDisplayId)) { if (lineDisplay != null) { var position = new Point(0, 0); if (CenterCheckBox.IsChecked.Value) { var length = text.Length; if (length < lineDisplay.DefaultWindow.SizeInCharacters.Width) { position.X = ((int)lineDisplay.DefaultWindow.SizeInCharacters.Width - length) / 2; } } LineDisplayTextAttribute attribute = LineDisplayTextAttribute.Normal; // If blinking is requested, verify that the device supports blinking. if (BlinkCheckBox.IsChecked.Value) { if (lineDisplay.Capabilities.CanBlink == LineDisplayTextAttributeGranularity.NotSupported) { BlinkNotSupportedText.Visibility = Visibility.Visible; } else { // Device supports blinking. attribute = LineDisplayTextAttribute.Blink; } } if (await lineDisplay.DefaultWindow.TryClearTextAsync() && await lineDisplay.DefaultWindow.TryDisplayTextAsync(text, attribute, position)) { rootPage.NotifyUser("Text displayed successfully", NotifyType.StatusMessage); } else { // We probably lost our claim. rootPage.NotifyUser("Unable to display text", NotifyType.ErrorMessage); } } else { rootPage.NotifyUser("Unable to claim the Line Display", NotifyType.ErrorMessage); } } }
public async Task <ClaimedLineDisplay> ClaimScenarioLineDisplayAsync() { ClaimedLineDisplay lineDisplay = null; if (String.IsNullOrEmpty(LineDisplayId)) { NotifyUser("You must use scenario 1 to select a line display", NotifyType.ErrorMessage); } else { lineDisplay = await ClaimedLineDisplay.FromIdAsync(LineDisplayId); if (lineDisplay == null) { NotifyUser("Unable to claim selected LineDisplay from id.", NotifyType.ErrorMessage); } } return(lineDisplay); }